(t *testing.T)
| 74 | } |
| 75 | |
| 76 | func TestAddSQLNullStringKey(t *testing.T) { |
| 77 | t.Run( |
| 78 | "AddSQLNullStringKey", |
| 79 | func(t *testing.T) { |
| 80 | testCases := []struct { |
| 81 | name string |
| 82 | sqlNullString sql.NullString |
| 83 | baseJSON string |
| 84 | expectedResult string |
| 85 | err bool |
| 86 | }{ |
| 87 | { |
| 88 | name: "it should encode a null string", |
| 89 | sqlNullString: sql.NullString{ |
| 90 | String: "foo bar", |
| 91 | }, |
| 92 | baseJSON: "{", |
| 93 | expectedResult: `{"foo":"foo bar"`, |
| 94 | }, |
| 95 | { |
| 96 | name: "it should encode a null string", |
| 97 | sqlNullString: sql.NullString{ |
| 98 | String: "foo \t bar", |
| 99 | }, |
| 100 | baseJSON: "{", |
| 101 | expectedResult: `{"foo":"foo \t bar"`, |
| 102 | }, |
| 103 | { |
| 104 | name: "it should encode a null string", |
| 105 | sqlNullString: sql.NullString{ |
| 106 | String: "foo \t bar", |
| 107 | }, |
| 108 | baseJSON: "{", |
| 109 | expectedResult: `{"foo":"foo \t bar"`, |
| 110 | }, |
| 111 | } |
| 112 | |
| 113 | for _, testCase := range testCases { |
| 114 | t.Run(testCase.name, func(t *testing.T) { |
| 115 | var b strings.Builder |
| 116 | enc := NewEncoder(&b) |
| 117 | enc.writeString(testCase.baseJSON) |
| 118 | enc.AddSQLNullStringKey("foo", &testCase.sqlNullString) |
| 119 | enc.Write() |
| 120 | assert.Equal(t, testCase.expectedResult, b.String()) |
| 121 | |
| 122 | var b2 strings.Builder |
| 123 | enc = NewEncoder(&b2) |
| 124 | enc.writeString(testCase.baseJSON) |
| 125 | enc.SQLNullStringKey("foo", &testCase.sqlNullString) |
| 126 | enc.Write() |
| 127 | assert.Equal(t, testCase.expectedResult, b2.String()) |
| 128 | }) |
| 129 | } |
| 130 | }, |
| 131 | ) |
| 132 | t.Run( |
| 133 | "AddSQLNullStringKeyOmitEmpty, is should encode a sql.NullString", |
nothing calls this directly
no test coverage detected
searching dependent graphs…