From 30ed2733d591124dc5a7ada7dfff38c72223296c Mon Sep 17 00:00:00 2001 From: Shawn Reuland Date: Tue, 17 Oct 2023 14:33:53 -0700 Subject: [PATCH] #4909: fixed json column tests on fast batch builder --- support/db/fast_batch_insert_builder_test.go | 15 ++++++++------- support/db/main_test.go | 9 +++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/support/db/fast_batch_insert_builder_test.go b/support/db/fast_batch_insert_builder_test.go index 2d55c8446a..bfd2f8407b 100644 --- a/support/db/fast_batch_insert_builder_test.go +++ b/support/db/fast_batch_insert_builder_test.go @@ -4,6 +4,7 @@ import ( "context" "testing" + "github.com/guregu/null" "github.com/stretchr/testify/assert" "github.com/stellar/go/support/db/dbtest" @@ -21,7 +22,7 @@ func TestFastBatchInsertBuilder(t *testing.T) { insertBuilder.Row(map[string]interface{}{ "name": "bubba", "hunger_level": "1", - "json_value": []byte(`{\"bump_to\":\"98\"}`), + "json_value": []byte(`{"bump_to": "97"}`), }), ) @@ -36,7 +37,7 @@ func TestFastBatchInsertBuilder(t *testing.T) { insertBuilder.Row(map[string]interface{}{ "name": "bubba", "city": "London", - "json_value": []byte(`{\"bump_to\":\"98\"}`), + "json_value": []byte(`{"bump_to": "98"}`), }), "column \"hunger_level\" does not exist", ) @@ -45,7 +46,7 @@ func TestFastBatchInsertBuilder(t *testing.T) { insertBuilder.RowStruct(hungerRow{ Name: "bubba2", HungerLevel: "9", - JsonValue: []byte(`{\"bump_to\":\"98\"}`), + JsonValue: []byte(`{"bump_to": "98"}`), }), ) @@ -77,8 +78,8 @@ func TestFastBatchInsertBuilder(t *testing.T) { t, found, []person{ - {Name: "bubba", HungerLevel: "1"}, - {Name: "bubba2", HungerLevel: "9"}, + {Name: "bubba", HungerLevel: "1", JsonValue: null.NewString(`{"bump_to": "97"}`, true)}, + {Name: "bubba2", HungerLevel: "9", JsonValue: null.NewString(`{"bump_to": "98"}`, true)}, }, ) @@ -119,8 +120,8 @@ func TestFastBatchInsertBuilder(t *testing.T) { t, found, []person{ - {Name: "bubba", HungerLevel: "1"}, - {Name: "bubba2", HungerLevel: "9"}, + {Name: "bubba", HungerLevel: "1", JsonValue: null.NewString(`{"bump_to": "97"}`, true)}, + {Name: "bubba2", HungerLevel: "9", JsonValue: null.NewString(`{"bump_to": "98"}`, true)}, }, ) assert.NoError(t, sess.Rollback()) diff --git a/support/db/main_test.go b/support/db/main_test.go index 68724d197d..301b533aa4 100644 --- a/support/db/main_test.go +++ b/support/db/main_test.go @@ -4,15 +4,16 @@ import ( "testing" "time" + "github.com/guregu/null" "github.com/stellar/go/support/db/dbtest" "github.com/stretchr/testify/assert" ) type person struct { - Name string `db:"name"` - HungerLevel string `db:"hunger_level"` - - SomethingIgnored int `db:"-"` + Name string `db:"name"` + HungerLevel string `db:"hunger_level"` + JsonValue null.String `db:"json_value"` + SomethingIgnored int `db:"-"` } func TestGetTable(t *testing.T) {