NullBool
(t *testing.T)
| 844 | |
| 845 | // NullBool |
| 846 | func TestEncoceSQLNullBool(t *testing.T) { |
| 847 | testCases := []struct { |
| 848 | name string |
| 849 | sqlNullBool sql.NullBool |
| 850 | expectedResult string |
| 851 | err bool |
| 852 | }{ |
| 853 | { |
| 854 | name: "it should encode a null string", |
| 855 | sqlNullBool: sql.NullBool{ |
| 856 | Bool: true, |
| 857 | }, |
| 858 | expectedResult: `true`, |
| 859 | }, |
| 860 | { |
| 861 | name: "it should return an err as the string is invalid", |
| 862 | sqlNullBool: sql.NullBool{ |
| 863 | Bool: false, |
| 864 | }, |
| 865 | expectedResult: `false`, |
| 866 | }, |
| 867 | } |
| 868 | |
| 869 | for _, testCase := range testCases { |
| 870 | t.Run(testCase.name, func(t *testing.T) { |
| 871 | var b strings.Builder |
| 872 | enc := NewEncoder(&b) |
| 873 | err := enc.EncodeSQLNullBool(&testCase.sqlNullBool) |
| 874 | if testCase.err { |
| 875 | assert.NotNil(t, err) |
| 876 | } else { |
| 877 | assert.Nil(t, err) |
| 878 | assert.Equal(t, testCase.expectedResult, b.String()) |
| 879 | } |
| 880 | }) |
| 881 | } |
| 882 | t.Run( |
| 883 | "should panic as the encoder is pooled", |
| 884 | func(t *testing.T) { |
| 885 | builder := &strings.Builder{} |
| 886 | enc := NewEncoder(builder) |
| 887 | enc.isPooled = 1 |
| 888 | defer func() { |
| 889 | err := recover() |
| 890 | assert.NotNil(t, err, "err should not be nil") |
| 891 | assert.IsType(t, InvalidUsagePooledEncoderError(""), err, "err should be of type InvalidUsagePooledEncoderError") |
| 892 | }() |
| 893 | _ = enc.EncodeSQLNullBool(&sql.NullBool{}) |
| 894 | assert.True(t, false, "should not be called as encoder should have panicked") |
| 895 | }, |
| 896 | ) |
| 897 | |
| 898 | t.Run( |
| 899 | "should return an error as the writer encounters an error", |
| 900 | func(t *testing.T) { |
| 901 | builder := TestWriterError("") |
| 902 | enc := NewEncoder(builder) |
| 903 | err := enc.EncodeSQLNullBool(&sql.NullBool{}) |
nothing calls this directly
no test coverage detected
searching dependent graphs…