本文整理匯總了Golang中github.com/mdlayher/goat/goat/data.FileRecord.Load方法的典型用法代碼示例。如果您正苦於以下問題:Golang FileRecord.Load方法的具體用法?Golang FileRecord.Load怎麽用?Golang FileRecord.Load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mdlayher/goat/goat/data.FileRecord
的用法示例。
在下文中一共展示了FileRecord.Load方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestGetFilesJSON
// TestGetFilesJSON verifies that /api/files returns proper JSON output
func TestGetFilesJSON(t *testing.T) {
log.Println("TestGetFilesJSON()")
// Load config
config := common.LoadConfig()
common.Static.Config = config
// Generate mock data.FileRecord
file := data.FileRecord{
InfoHash: "deadbeef",
Verified: true,
}
// Save mock file
if !file.Save() {
t.Fatalf("Failed to save mock file")
}
// Load mock file to fetch ID
file = file.Load(file.InfoHash, "info_hash")
if file == (data.FileRecord{}) {
t.Fatalf("Failed to load mock file")
}
// Request output JSON from API for this file
var file2 data.FileRecord
err := json.Unmarshal(getFilesJSON(file.ID), &file2)
if err != nil {
t.Fatalf("Failed to unmarshal result JSON for single file")
}
// Verify objects are the same
if file.ID != file2.ID {
t.Fatalf("ID, expected %d, got %d", file.ID, file2.ID)
}
// Request output JSON from API for all files
var allFiles []data.FileRecord
err = json.Unmarshal(getFilesJSON(-1), &allFiles)
if err != nil {
t.Fatalf("Failed to unmarshal result JSON for all files")
}
// Verify known file is in result set
found := false
for _, f := range allFiles {
if f.ID == file.ID {
found = true
}
}
if !found {
t.Fatalf("Expected file not found in all files result set")
}
// Delete mock file
if !file.Delete() {
t.Fatalf("Failed to delete mock file")
}
}