Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: improve mysql_z_unit_model_test #3329

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 38 additions & 2 deletions contrib/drivers/mysql/mysql_z_unit_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3646,7 +3646,7 @@ func Test_Model_OnDuplicate(t *testing.T) {
table := createInitTable()
defer dropTable(table)

// string.
// string type 1.
gtest.C(t, func(t *gtest.T) {
data := g.Map{
"id": 1,
Expand All @@ -3664,6 +3664,24 @@ func Test_Model_OnDuplicate(t *testing.T) {
t.Assert(one["nickname"], "name_1")
})

// string type 2.
gtest.C(t, func(t *gtest.T) {
data := g.Map{
"id": 1,
"passport": "pp1",
"password": "pw1",
"nickname": "n1",
"create_time": "2016-06-06",
}
_, err := db.Model(table).OnDuplicate("passport", "password").Data(data).Save()
t.AssertNil(err)
one, err := db.Model(table).WherePri(1).One()
t.AssertNil(err)
t.Assert(one["passport"], data["passport"])
t.Assert(one["password"], data["password"])
t.Assert(one["nickname"], "name_1")
})

// slice.
gtest.C(t, func(t *gtest.T) {
data := g.Map{
Expand Down Expand Up @@ -3729,7 +3747,7 @@ func Test_Model_OnDuplicateEx(t *testing.T) {
table := createInitTable()
defer dropTable(table)

// string.
// string type 1.
gtest.C(t, func(t *gtest.T) {
data := g.Map{
"id": 1,
Expand All @@ -3747,6 +3765,24 @@ func Test_Model_OnDuplicateEx(t *testing.T) {
t.Assert(one["nickname"], "name_1")
})

// string type 2.
gtest.C(t, func(t *gtest.T) {
data := g.Map{
"id": 1,
"passport": "pp1",
"password": "pw1",
"nickname": "n1",
"create_time": "2016-06-06",
}
_, err := db.Model(table).OnDuplicateEx("nickname", "create_time").Data(data).Save()
t.AssertNil(err)
one, err := db.Model(table).WherePri(1).One()
t.AssertNil(err)
t.Assert(one["passport"], data["passport"])
t.Assert(one["password"], data["password"])
t.Assert(one["nickname"], "name_1")
})

// slice.
gtest.C(t, func(t *gtest.T) {
data := g.Map{
Expand Down