本文整理匯總了Golang中github.com/mdlayher/goat/goat/data.UserRecord.Delete方法的典型用法代碼示例。如果您正苦於以下問題:Golang UserRecord.Delete方法的具體用法?Golang UserRecord.Delete怎麽用?Golang UserRecord.Delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mdlayher/goat/goat/data.UserRecord
的用法示例。
在下文中一共展示了UserRecord.Delete方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestBasicAuthenticator
// TestBasicAuthenticator verifies that BasicAuthenticator.Auth works properly
func TestBasicAuthenticator(t *testing.T) {
log.Println("TestBasicAuthenticator()")
// Load config
config := common.LoadConfig()
common.Static.Config = config
// Generate mock user
user := data.UserRecord{
Username: "test",
Passkey: "abcdef0123456789",
TorrentLimit: 10,
}
// Save mock user
if !user.Save() {
t.Fatalf("Failed to save mock user")
}
// Load mock user to fetch ID
user = user.Load(user.Username, "username")
if user == (data.UserRecord{}) {
t.Fatalf("Failed to load mock user")
}
// Generate an API key and salt
pass := "deadbeef"
salt := "test"
sha := sha1.New()
sha.Write([]byte(pass + salt))
hash := fmt.Sprintf("%x", sha.Sum(nil))
// Generate mock API key
key := data.APIKey{
UserID: user.ID,
Key: hash,
Salt: salt,
}
// Save mock API key
if !key.Save() {
t.Fatalf("Failed to save mock data.APIKey")
}
// Load mock data.APIKey to fetch ID
key = key.Load(key.Key, "key")
if key == (data.APIKey{}) {
t.Fatalf("Failed to load mock data.APIKey")
}
// Generate mock HTTP request
r := http.Request{}
headers := map[string][]string{
"Authorization": {"Basic " + base64.URLEncoding.EncodeToString([]byte(user.Username+":"+pass))},
}
r.Header = headers
// Perform authentication request
auth := new(BasicAuthenticator).Auth(&r)
if !auth {
t.Fatalf("Failed to authenticate using BasicAuthenticator")
}
// Delete mock user
if !user.Delete() {
t.Fatalf("Failed to delete mock user")
}
// Delete mock API key
if !key.Delete() {
t.Fatalf("Failed to delete mock data.APIKey")
}
}