MCPcopy
hub / github.com/gogf/gf / TestDoInsert

Function TestDoInsert

contrib/drivers/mssql/mssql_z_unit_basic_test.go:117–155  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

115}
116
117func TestDoInsert(t *testing.T) {
118 gtest.C(t, func(t *gtest.T) {
119 createTable("t_user")
120 defer dropTable("t_user")
121
122 i := 10
123 data := g.Map{
124 "id": i,
125 "passport": fmt.Sprintf(`t%d`, i),
126 "password": fmt.Sprintf(`p%d`, i),
127 "nickname": fmt.Sprintf(`T%d`, i),
128 "create_time": gtime.Now(),
129 }
130 _, err := db.Insert(context.Background(), "t_user", data)
131 gtest.AssertNil(err)
132
133 })
134
135 gtest.C(t, func(t *gtest.T) {
136 createTable("t_user")
137 defer dropTable("t_user")
138
139 i := 10
140 data := g.Map{
141 // "id": i,
142 "passport": fmt.Sprintf(`t%d`, i),
143 "password": fmt.Sprintf(`p%d`, i),
144 "nickname": fmt.Sprintf(`T%d`, i),
145 "create_time": gtime.Now(),
146 }
147 // Save without OnConflict should fail (missing conflict columns)
148 _, err := db.Save(context.Background(), "t_user", data, 10)
149 gtest.AssertNE(err, nil)
150
151 // Replace should fail because primary key 'id' is not in the data
152 _, err = db.Replace(context.Background(), "t_user", data, 10)
153 gtest.AssertNE(err, nil)
154 })
155}
156
157func TestDoInsertGetId(t *testing.T) {
158 // create test table

Callers

nothing calls this directly

Calls 9

CFunction · 0.92
NowFunction · 0.92
AssertNilFunction · 0.92
AssertNEFunction · 0.92
createTableFunction · 0.70
dropTableFunction · 0.70
InsertMethod · 0.65
SaveMethod · 0.65
ReplaceMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…