NullInt64
(t *testing.T)
| 289 | |
| 290 | // NullInt64 |
| 291 | func TestEncoceSQLNullInt64(t *testing.T) { |
| 292 | testCases := []struct { |
| 293 | name string |
| 294 | sqlNullInt64 sql.NullInt64 |
| 295 | expectedResult string |
| 296 | err bool |
| 297 | }{ |
| 298 | { |
| 299 | name: "it should encode a null string", |
| 300 | sqlNullInt64: sql.NullInt64{ |
| 301 | Int64: int64(1), |
| 302 | }, |
| 303 | expectedResult: `1`, |
| 304 | }, |
| 305 | { |
| 306 | name: "it should return an err as the string is invalid", |
| 307 | sqlNullInt64: sql.NullInt64{ |
| 308 | Int64: int64(2), |
| 309 | }, |
| 310 | expectedResult: `2`, |
| 311 | }, |
| 312 | } |
| 313 | |
| 314 | for _, testCase := range testCases { |
| 315 | t.Run(testCase.name, func(t *testing.T) { |
| 316 | var b strings.Builder |
| 317 | enc := NewEncoder(&b) |
| 318 | err := enc.EncodeSQLNullInt64(&testCase.sqlNullInt64) |
| 319 | if testCase.err { |
| 320 | assert.NotNil(t, err) |
| 321 | } else { |
| 322 | assert.Nil(t, err) |
| 323 | assert.Equal(t, testCase.expectedResult, b.String()) |
| 324 | } |
| 325 | }) |
| 326 | } |
| 327 | t.Run( |
| 328 | "should panic as the encoder is pooled", |
| 329 | func(t *testing.T) { |
| 330 | builder := &strings.Builder{} |
| 331 | enc := NewEncoder(builder) |
| 332 | enc.isPooled = 1 |
| 333 | defer func() { |
| 334 | err := recover() |
| 335 | assert.NotNil(t, err, "err should not be nil") |
| 336 | assert.IsType(t, InvalidUsagePooledEncoderError(""), err, "err should be of type InvalidUsagePooledEncoderError") |
| 337 | }() |
| 338 | _ = enc.EncodeSQLNullInt64(&sql.NullInt64{}) |
| 339 | assert.True(t, false, "should not be called as encoder should have panicked") |
| 340 | }, |
| 341 | ) |
| 342 | t.Run( |
| 343 | "should return an error as the writer encounters an error", |
| 344 | func(t *testing.T) { |
| 345 | builder := TestWriterError("") |
| 346 | enc := NewEncoder(builder) |
| 347 | err := enc.EncodeSQLNullInt64(&sql.NullInt64{}) |
| 348 | assert.NotNil(t, err) |
nothing calls this directly
no test coverage detected
searching dependent graphs…