MCPcopy Create free account
hub / github.com/francoispqt/gojay / TestDecodeSQLNullString

Function TestDecodeSQLNullString

decode_sqlnull_test.go:12–58  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func 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
60func TestDecodeSQLNullInt64(t *testing.T) {
61 testCases := []struct {

Callers

nothing calls this directly

Calls 4

DecodeSQLNullStringMethod · 0.95
ReleaseMethod · 0.95
NewDecoderFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…