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

Function TestEncoceSQLNullBool

encode_sqlnull_test.go:846–907  ·  view source on GitHub ↗

NullBool

(t *testing.T)

Source from the content-addressed store, hash-verified

844
845// NullBool
846func 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{})

Callers

nothing calls this directly

Calls 5

EncodeSQLNullBoolMethod · 0.95
NewEncoderFunction · 0.85
TestWriterErrorTypeAlias · 0.85
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…