(t *testing.T)
| 95 | } |
| 96 | |
| 97 | func 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 | |
| 134 | func Test_DB_GetAll(t *testing.T) { |
| 135 | table := createInitTable() |
nothing calls this directly
no test coverage detected
searching dependent graphs…