我必须编写用于插入、获取、删除和更新数据的测试用例。在互联网上搜索时,我找到了一个代码并且它可以工作,但我不知道它是如何工作的。我的代码在下面给出,任何人都可以用简单的方式告诉我我将如何理解代码。
package models
import(
"testing"
"gopkg.in/mgo.v2/bson"
"fmt"
)
func TestAddBlog(t *testing.T) {
type args struct{
query interface{}
}
tests := []struct{
name string
args args
want bool
}{
{
"first",
args{
bson.M{
"_id" : 4,
"title" : "Life",
"type" : "Motivation",
"description" : "If you skip anything then you will fail in the race of the life....",
"profile_image" : "/image1",
"date_time" : 1536062976,
"author" : "Charliee",
"status" : 1,
"slug" : "abc",
"comment_count" : 100,
"comment_status" : "q",
},
},
true,
},
{
"second",
args{
bson.M{
"_id" : 5,
"title" : "Life",
"type" : "Motivation",
"description" : "If you skip anything then you will fail in the race of the life....",
"profile_image" : "/image1",
"date_time" : 1536062976,
"author" : "Charliee",
"status" : 1,
"slug" : "abc",
"comment_count" : 100,
"comment_status" : "q",
},
},
false,
},
}
for _, k := range tests {
t.Run(k.name, func (t *testing.T) {
err := AddBlog(k.args.query)
fmt.Println(err)
})
}
}
子衿沉夜
相关分类