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

Function TestEncoceSQLNullFloat64

encode_sqlnull_test.go:568–629  ·  view source on GitHub ↗

NullFloat64

(t *testing.T)

Source from the content-addressed store, hash-verified

566
567// NullFloat64
568func TestEncoceSQLNullFloat64(t *testing.T) {
569 testCases := []struct {
570 name string
571 sqlNullFloat64 sql.NullFloat64
572 expectedResult string
573 err bool
574 }{
575 {
576 name: "it should encode a null string",
577 sqlNullFloat64: sql.NullFloat64{
578 Float64: float64(1),
579 },
580 expectedResult: `1`,
581 },
582 {
583 name: "it should return an err as the string is invalid",
584 sqlNullFloat64: sql.NullFloat64{
585 Float64: float64(2),
586 },
587 expectedResult: `2`,
588 },
589 }
590
591 for _, testCase := range testCases {
592 t.Run(testCase.name, func(t *testing.T) {
593 var b strings.Builder
594 enc := NewEncoder(&b)
595 err := enc.EncodeSQLNullFloat64(&testCase.sqlNullFloat64)
596 if testCase.err {
597 assert.NotNil(t, err)
598 } else {
599 assert.Nil(t, err)
600 assert.Equal(t, testCase.expectedResult, b.String())
601 }
602 })
603 }
604 t.Run(
605 "should panic as the encoder is pooled",
606 func(t *testing.T) {
607 builder := &strings.Builder{}
608 enc := NewEncoder(builder)
609 enc.isPooled = 1
610 defer func() {
611 err := recover()
612 assert.NotNil(t, err, "err should not be nil")
613 assert.IsType(t, InvalidUsagePooledEncoderError(""), err, "err should be of type InvalidUsagePooledEncoderError")
614 }()
615 _ = enc.EncodeSQLNullFloat64(&sql.NullFloat64{})
616 assert.True(t, false, "should not be called as encoder should have panicked")
617 },
618 )
619
620 t.Run(
621 "should return an error as the writer encounters an error",
622 func(t *testing.T) {
623 builder := TestWriterError("")
624 enc := NewEncoder(builder)
625 err := enc.EncodeSQLNullFloat64(&sql.NullFloat64{})

Callers

nothing calls this directly

Calls 5

EncodeSQLNullFloat64Method · 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…