Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Commit

Permalink
go livesql: Add implicitnull binlog test
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Hughes authored and willhug committed Oct 9, 2018
1 parent 48ce76b commit 977f2bb
Showing 1 changed file with 42 additions and 21 deletions.
63 changes: 42 additions & 21 deletions livesql/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import (
)

type User struct {
Id int64 `sql:",primary"`
Name string
Uuid testfixtures.CustomType
Mood *testfixtures.CustomType
Id int64 `sql:",primary"`
Name string
Uuid testfixtures.CustomType
Mood *testfixtures.CustomType
ImplicitNullStr string `sql:,implicitnull`
}

func TestIntegrationBasic(t *testing.T) {
Expand All @@ -36,7 +37,8 @@ func TestIntegrationBasic(t *testing.T) {
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
uuid VARCHAR(255),
mood VARCHAR(255)
mood VARCHAR(255),
implicit_null_str VARCHAR(255)
)
`)
if err != nil {
Expand All @@ -55,6 +57,8 @@ func TestIntegrationBasic(t *testing.T) {
newMood := testfixtures.CustomTypeFromString("outrage")
uuid := testfixtures.CustomTypeFromString("11238491293")
newUuid := testfixtures.CustomTypeFromString("11232481203")
implicitNullStr := ""
newImplicitNullStr := "not null"

result, err := db.InsertRow(context.Background(), &User{Name: name, Uuid: uuid, Mood: &mood})
assert.NoError(t, err)
Expand All @@ -74,22 +78,32 @@ func TestIntegrationBasic(t *testing.T) {
defer rerunner.Stop()

// Initial rerunner query matches initial insert.
assert.Equal(t, User{Id: userId, Name: name, Uuid: uuid, Mood: &mood}, <-users)
assert.Equal(t, User{Id: userId, Name: name, Uuid: uuid, Mood: &mood, ImplicitNullStr: implicitNullStr}, <-users)

// Upon update we get another rerunner result with the updated name.
err = db.UpdateRow(context.Background(), &User{Id: userId, Name: newName, Uuid: uuid, Mood: &mood})
err = db.UpdateRow(context.Background(), &User{Id: userId, Name: newName, Uuid: uuid, Mood: &mood, ImplicitNullStr: implicitNullStr})
assert.NoError(t, err)
assert.Equal(t, User{Id: userId, Name: newName, Uuid: uuid, Mood: &mood}, <-users)
assert.Equal(t, User{Id: userId, Name: newName, Uuid: uuid, Mood: &mood, ImplicitNullStr: implicitNullStr}, <-users)

// Upon update we get another rerunner result with the updated uuid.
err = db.UpdateRow(context.Background(), &User{Id: userId, Name: newName, Uuid: newUuid, Mood: &mood})
err = db.UpdateRow(context.Background(), &User{Id: userId, Name: newName, Uuid: newUuid, Mood: &mood, ImplicitNullStr: implicitNullStr})
assert.NoError(t, err)
assert.Equal(t, User{Id: userId, Name: newName, Uuid: newUuid, Mood: &mood}, <-users)
assert.Equal(t, User{Id: userId, Name: newName, Uuid: newUuid, Mood: &mood, ImplicitNullStr: implicitNullStr}, <-users)

// Upon update we get another rerunner result with the updated mood.
err = db.UpdateRow(context.Background(), &User{Id: userId, Name: newName, Uuid: newUuid, Mood: &newMood})
err = db.UpdateRow(context.Background(), &User{Id: userId, Name: newName, Uuid: newUuid, Mood: &newMood, ImplicitNullStr: implicitNullStr})
assert.NoError(t, err)
assert.Equal(t, User{Id: userId, Name: newName, Uuid: newUuid, Mood: &newMood}, <-users)
assert.Equal(t, User{Id: userId, Name: newName, Uuid: newUuid, Mood: &newMood, ImplicitNullStr: implicitNullStr}, <-users)

// Upon update we get another rerunner result with the updated implicitNullStr.
err = db.UpdateRow(context.Background(), &User{Id: userId, Name: newName, Uuid: newUuid, Mood: &newMood, ImplicitNullStr: newImplicitNullStr})
assert.NoError(t, err)
assert.Equal(t, User{Id: userId, Name: newName, Uuid: newUuid, Mood: &newMood, ImplicitNullStr: newImplicitNullStr}, <-users)

// Upon update we get another rerunner result with the original implicitNullStr.
err = db.UpdateRow(context.Background(), &User{Id: userId, Name: newName, Uuid: newUuid, Mood: &newMood, ImplicitNullStr: implicitNullStr})
assert.NoError(t, err)
assert.Equal(t, User{Id: userId, Name: newName, Uuid: newUuid, Mood: &newMood, ImplicitNullStr: implicitNullStr}, <-users)
}

func TestIntegrationFilterCustomType(t *testing.T) {
Expand All @@ -107,7 +121,8 @@ func TestIntegrationFilterCustomType(t *testing.T) {
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
uuid VARCHAR(255),
mood VARCHAR(255)
mood VARCHAR(255),
implicit_null_str VARCHAR(255)
)
`)
if err != nil {
Expand All @@ -126,8 +141,10 @@ func TestIntegrationFilterCustomType(t *testing.T) {
newMood := testfixtures.CustomTypeFromString("outrage")
uuid := testfixtures.CustomTypeFromString("11238491293")
newUuid := testfixtures.CustomTypeFromString("11232481203")
implicitNullStr := ""
newImplicitNullStr := "not null"

result, err := db.InsertRow(context.Background(), &User{Name: name, Uuid: uuid, Mood: &mood})
result, err := db.InsertRow(context.Background(), &User{Name: name, Uuid: uuid, Mood: &mood, ImplicitNullStr: implicitNullStr})
assert.NoError(t, err)
userId, err := result.LastInsertId()
assert.NoError(t, err)
Expand All @@ -140,28 +157,32 @@ func TestIntegrationFilterCustomType(t *testing.T) {
if err := db.QueryRow(ctx, &user, sqlgen.Filter{"mood": &mood}, nil); err != nil {
users <- nil
return nil, nil
// t.Errorf("couldn't query row: %v", err)
}
users <- user
return nil, nil
}, 50*time.Millisecond)
defer rerunner.Stop()

// Initial rerunner query matches initial insert.
assert.Equal(t, &User{Id: userId, Name: name, Uuid: uuid, Mood: &mood}, <-users)
assert.Equal(t, &User{Id: userId, Name: name, Uuid: uuid, Mood: &mood, ImplicitNullStr: implicitNullStr}, <-users)

// Upon update we get another rerunner result with the updated name.
err = db.UpdateRow(context.Background(), &User{Id: userId, Name: newName, Uuid: uuid, Mood: &mood})
err = db.UpdateRow(context.Background(), &User{Id: userId, Name: newName, Uuid: uuid, Mood: &mood, ImplicitNullStr: implicitNullStr})
assert.NoError(t, err)
assert.Equal(t, &User{Id: userId, Name: newName, Uuid: uuid, Mood: &mood}, <-users)
assert.Equal(t, &User{Id: userId, Name: newName, Uuid: uuid, Mood: &mood, ImplicitNullStr: implicitNullStr}, <-users)

// Upon update we get another rerunner result with the updated uuid.
err = db.UpdateRow(context.Background(), &User{Id: userId, Name: newName, Uuid: newUuid, Mood: &mood})
err = db.UpdateRow(context.Background(), &User{Id: userId, Name: newName, Uuid: newUuid, Mood: &mood, ImplicitNullStr: implicitNullStr})
assert.NoError(t, err)
assert.Equal(t, &User{Id: userId, Name: newName, Uuid: newUuid, Mood: &mood, ImplicitNullStr: implicitNullStr}, <-users)

// Upon update we get another rerunner result with the updated implicitNullStr.
err = db.UpdateRow(context.Background(), &User{Id: userId, Name: newName, Uuid: newUuid, Mood: &mood, ImplicitNullStr: newImplicitNullStr})
assert.NoError(t, err)
assert.Equal(t, &User{Id: userId, Name: newName, Uuid: newUuid, Mood: &mood}, <-users)
assert.Equal(t, &User{Id: userId, Name: newName, Uuid: newUuid, Mood: &mood, ImplicitNullStr: newImplicitNullStr}, <-users)

// Upon update we get another rerunner result with the updated mood.
err = db.UpdateRow(context.Background(), &User{Id: userId, Name: newName, Uuid: newUuid, Mood: &newMood})
err = db.UpdateRow(context.Background(), &User{Id: userId, Name: newName, Uuid: newUuid, Mood: &newMood, ImplicitNullStr: implicitNullStr})
assert.NoError(t, err)
assert.Equal(t, (*User)(nil), <-users)
}

0 comments on commit 977f2bb

Please sign in to comment.