(t *testing.T)
| 907 | } |
| 908 | |
| 909 | func TestAddSQLNullBoolKey(t *testing.T) { |
| 910 | t.Run( |
| 911 | "AddSQLNullBoolKey", |
| 912 | func(t *testing.T) { |
| 913 | testCases := []struct { |
| 914 | name string |
| 915 | sqlNullBool sql.NullBool |
| 916 | baseJSON string |
| 917 | expectedResult string |
| 918 | err bool |
| 919 | }{ |
| 920 | { |
| 921 | name: "it should encode a null string", |
| 922 | sqlNullBool: sql.NullBool{ |
| 923 | Bool: true, |
| 924 | }, |
| 925 | baseJSON: "{", |
| 926 | expectedResult: `{"foo":true`, |
| 927 | }, |
| 928 | { |
| 929 | name: "it should encode a null string", |
| 930 | sqlNullBool: sql.NullBool{ |
| 931 | Bool: false, |
| 932 | }, |
| 933 | baseJSON: "{", |
| 934 | expectedResult: `{"foo":false`, |
| 935 | }, |
| 936 | { |
| 937 | name: "it should encode a null string", |
| 938 | sqlNullBool: sql.NullBool{ |
| 939 | Bool: true, |
| 940 | }, |
| 941 | baseJSON: "{", |
| 942 | expectedResult: `{"foo":true`, |
| 943 | }, |
| 944 | } |
| 945 | |
| 946 | for _, testCase := range testCases { |
| 947 | t.Run(testCase.name, func(t *testing.T) { |
| 948 | var b strings.Builder |
| 949 | enc := NewEncoder(&b) |
| 950 | enc.writeString(testCase.baseJSON) |
| 951 | enc.AddSQLNullBoolKey("foo", &testCase.sqlNullBool) |
| 952 | enc.Write() |
| 953 | assert.Equal(t, testCase.expectedResult, b.String()) |
| 954 | |
| 955 | var b2 strings.Builder |
| 956 | enc = NewEncoder(&b2) |
| 957 | enc.writeString(testCase.baseJSON) |
| 958 | enc.SQLNullBoolKey("foo", &testCase.sqlNullBool) |
| 959 | enc.Write() |
| 960 | assert.Equal(t, testCase.expectedResult, b2.String()) |
| 961 | }) |
| 962 | } |
| 963 | }, |
| 964 | ) |
| 965 | t.Run( |
| 966 | "AddSQLNullBoolKeyOmitEmpty, is should encode a sql.NullBool", |
nothing calls this directly
no test coverage detected
searching dependent graphs…