(t *testing.T)
| 437 | } |
| 438 | |
| 439 | func TestScanGetResponseLine(t *testing.T) { |
| 440 | tests := []struct { |
| 441 | name string |
| 442 | line string |
| 443 | wantKey string |
| 444 | wantFlags uint32 |
| 445 | wantCasid uint64 |
| 446 | wantSize int |
| 447 | wantErr bool |
| 448 | }{ |
| 449 | {name: "blank", line: "", |
| 450 | wantErr: true}, |
| 451 | {name: "malformed1", line: "VALU foobar1234 1 4096\r\n", |
| 452 | wantErr: true}, |
| 453 | {name: "malformed2", line: "VALUEfoobar1234 1 4096\r\n", |
| 454 | wantErr: true}, |
| 455 | {name: "malformed3", line: "VALUE foobar1234 14096\r\n", |
| 456 | wantErr: true}, |
| 457 | {name: "malformed4", line: "VALUE foobar123414096\r\n", |
| 458 | wantErr: true}, |
| 459 | {name: "no-eol", line: "VALUE foobar1234 1 4096", |
| 460 | wantErr: true}, |
| 461 | {name: "basic", line: "VALUE foobar1234 1 4096\r\n", |
| 462 | wantKey: "foobar1234", wantFlags: 1, wantSize: 4096}, |
| 463 | {name: "casid", line: "VALUE foobar1234 1 4096 1234\r\n", |
| 464 | wantKey: "foobar1234", wantFlags: 1, wantSize: 4096, wantCasid: 1234}, |
| 465 | {name: "flags-max-uint32", line: "VALUE key 4294967295 1\r\n", |
| 466 | wantKey: "key", wantFlags: 4294967295, wantSize: 1}, |
| 467 | {name: "flags-overflow", line: "VALUE key 4294967296 1\r\n", |
| 468 | wantErr: true}, |
| 469 | {name: "size-max-uint32", line: "VALUE key 1 2147483647\r\n", |
| 470 | wantKey: "key", wantFlags: 1, wantSize: 2147483647}, |
| 471 | {name: "size-overflow", line: "VALUE key 1 4294967296\r\n", |
| 472 | wantErr: true}, |
| 473 | {name: "casid-overflow", line: "VALUE key 1 4096 18446744073709551616\r\n", |
| 474 | wantErr: true}, |
| 475 | } |
| 476 | for _, tt := range tests { |
| 477 | t.Run(tt.name, func(t *testing.T) { |
| 478 | var got Item |
| 479 | gotSize, err := scanGetResponseLine([]byte(tt.line), &got) |
| 480 | if tt.wantErr { |
| 481 | if err == nil { |
| 482 | t.Errorf("scanGetResponseLine() should have returned error") |
| 483 | } |
| 484 | return |
| 485 | } |
| 486 | if err != nil { |
| 487 | t.Errorf("scanGetResponseLine() returned error %s", err) |
| 488 | return |
| 489 | } |
| 490 | if got.Key != tt.wantKey { |
| 491 | t.Errorf("key = %v, want %v", got.Key, tt.wantKey) |
| 492 | } |
| 493 | if got.Flags != tt.wantFlags { |
| 494 | t.Errorf("flags = %v, want %v", got.Flags, tt.wantFlags) |
| 495 | } |
| 496 | if got.CasID != tt.wantCasid { |
nothing calls this directly
no test coverage detected
searching dependent graphs…