(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestDecodeSQLNullString(t *testing.T) { |
| 13 | testCases := []struct { |
| 14 | name string |
| 15 | json string |
| 16 | expectedNullString sql.NullString |
| 17 | err bool |
| 18 | }{ |
| 19 | { |
| 20 | name: "basic", |
| 21 | json: `"test"`, |
| 22 | expectedNullString: sql.NullString{String: "test", Valid: true}, |
| 23 | }, |
| 24 | { |
| 25 | name: "basic", |
| 26 | json: `"test`, |
| 27 | expectedNullString: sql.NullString{String: "test", Valid: true}, |
| 28 | err: true, |
| 29 | }, |
| 30 | } |
| 31 | for _, testCase := range testCases { |
| 32 | t.Run(testCase.name, func(t *testing.T) { |
| 33 | nullString := sql.NullString{} |
| 34 | dec := NewDecoder(strings.NewReader(testCase.json)) |
| 35 | err := dec.DecodeSQLNullString(&nullString) |
| 36 | if testCase.err { |
| 37 | assert.NotNil(t, err) |
| 38 | } else { |
| 39 | assert.Nil(t, err) |
| 40 | assert.Equal(t, testCase.expectedNullString, nullString) |
| 41 | } |
| 42 | }) |
| 43 | } |
| 44 | t.Run( |
| 45 | "should panic because decoder is pooled", |
| 46 | func(t *testing.T) { |
| 47 | dec := NewDecoder(nil) |
| 48 | dec.Release() |
| 49 | defer func() { |
| 50 | err := recover() |
| 51 | assert.NotNil(t, err, "err shouldnt be nil") |
| 52 | assert.IsType(t, InvalidUsagePooledDecoderError(""), err, "err should be of type InvalidUsagePooledDecoderError") |
| 53 | }() |
| 54 | _ = dec.DecodeSQLNullString(&sql.NullString{}) |
| 55 | assert.True(t, false, "should not be called as decoder should have panicked") |
| 56 | }, |
| 57 | ) |
| 58 | } |
| 59 | |
| 60 | func TestDecodeSQLNullInt64(t *testing.T) { |
| 61 | testCases := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…