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

Function Test_DB_Replace

contrib/drivers/gaussdb/gaussdb_z_unit_db_test.go:97–132  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

95}
96
97func Test_DB_Replace(t *testing.T) {
98 gtest.C(t, func(t *gtest.T) {
99 createTable("t_user")
100 defer dropTable("t_user")
101
102 // Insert initial record
103 i := 10
104 data := g.Map{
105 "id": i,
106 "passport": fmt.Sprintf(`t%d`, i),
107 "password": fmt.Sprintf(`p%d`, i),
108 "nickname": fmt.Sprintf(`T%d`, i),
109 "create_time": gtime.Now().String(),
110 }
111 _, err := db.Insert(ctx, "t_user", data)
112 gtest.AssertNil(err)
113
114 // Replace with new data
115 data2 := g.Map{
116 "id": i,
117 "passport": fmt.Sprintf(`t%d_new`, i),
118 "password": fmt.Sprintf(`p%d_new`, i),
119 "nickname": fmt.Sprintf(`T%d_new`, i),
120 "create_time": gtime.Now().String(),
121 }
122 _, err = db.Replace(ctx, "t_user", data2)
123 gtest.AssertNil(err)
124
125 // Verify the data was replaced
126 one, err := db.GetOne(ctx, fmt.Sprintf("SELECT * FROM t_user WHERE id=?"), i)
127 gtest.AssertNil(err)
128 gtest.Assert(one["passport"].String(), fmt.Sprintf(`t%d_new`, i))
129 gtest.Assert(one["password"].String(), fmt.Sprintf(`p%d_new`, i))
130 gtest.Assert(one["nickname"].String(), fmt.Sprintf(`T%d_new`, i))
131 })
132}
133
134func Test_DB_GetAll(t *testing.T) {
135 table := createInitTable()

Callers

nothing calls this directly

Calls 10

CFunction · 0.92
NowFunction · 0.92
AssertNilFunction · 0.92
AssertFunction · 0.92
createTableFunction · 0.70
dropTableFunction · 0.70
StringMethod · 0.65
InsertMethod · 0.65
ReplaceMethod · 0.65
GetOneMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…