gitee.com/woood2/luca@v1.0.4/internal/repository/student_test.go (about) 1 package repository 2 3 import ( 4 "context" 5 "gitee.com/woood2/luca/internal/db" 6 "gitee.com/woood2/luca/internal/util" 7 "go.mongodb.org/mongo-driver/bson/primitive" 8 "log" 9 "testing" 10 ) 11 12 func TestCreateStudent(t *testing.T) { 13 util.SkipCI(t) 14 var tests = []struct { 15 name string 16 age int 17 }{ 18 {"qwj", 40}, 19 {"dzm", 35}, 20 } 21 for _, tt := range tests { 22 s := &Student{ 23 tt.name, 24 tt.age, 25 } 26 if id, err := CreateStudent(context.Background(), db.MongoDB(), s); err != nil { 27 t.Errorf("expected err=nil; actual id=%v, err=%v", id, err) 28 } else { 29 s := id.(primitive.ObjectID).Hex() 30 t := id.(primitive.ObjectID).Timestamp() 31 log.Printf("%s, %s, %v", id, s, t) 32 } 33 } 34 }