user_credential_test.go 741 字节
package userAuth

import (
	"strings"
	"testing"
)

func TestRedisUserCredential(t *testing.T) {
	initRedis()
	key := "18860183050"
	userAuth := NewRedisUserCredential(key)
	saveCredential := "123456789"
	var credential string
	err := userAuth.AddAuth(saveCredential)
	if err != nil {
		t.Fatal(err)
	}
	credential, err = userAuth.GetAuth()
	if err != nil {
		t.Fatal("get auth", err)
	}
	if !userAuth.Exist() {
		t.Fatal("except:true")
	}
	if !strings.EqualFold(credential, saveCredential) {
		t.Fatal("check credential:", err)
	}
	if err = userAuth.RemoveAuth(); err != nil {
		t.Fatal("remove:", err)
	}
	if v := userAuth.field(); v != "18860183050" {
		t.Fatal("except:18860183050 get:", v)
	}
	if userAuth.Exist() {
		t.Fatal(key)
	}
}