(t *testing.T)
| 505 | } |
| 506 | |
| 507 | func TestBoolQueryValue(t *testing.T) { |
| 508 | t.Run("True values", func(t *testing.T) { |
| 509 | for _, v := range []string{"true", "True", "TRUE", "1", "t", "yes"} { |
| 510 | query := make(map[string][]string) |
| 511 | query["key"] = []string{v} |
| 512 | value, ok := litestream.BoolQueryValue(query, "key") |
| 513 | if !ok { |
| 514 | t.Errorf("BoolQueryValue with %q should be ok", v) |
| 515 | } |
| 516 | if !value { |
| 517 | t.Errorf("BoolQueryValue with %q should be true", v) |
| 518 | } |
| 519 | } |
| 520 | }) |
| 521 | |
| 522 | t.Run("False values", func(t *testing.T) { |
| 523 | for _, v := range []string{"false", "False", "FALSE", "0", "f", "no"} { |
| 524 | query := make(map[string][]string) |
| 525 | query["key"] = []string{v} |
| 526 | value, ok := litestream.BoolQueryValue(query, "key") |
| 527 | if !ok { |
| 528 | t.Errorf("BoolQueryValue with %q should be ok", v) |
| 529 | } |
| 530 | if value { |
| 531 | t.Errorf("BoolQueryValue with %q should be false", v) |
| 532 | } |
| 533 | } |
| 534 | }) |
| 535 | |
| 536 | t.Run("Missing key", func(t *testing.T) { |
| 537 | query := make(map[string][]string) |
| 538 | _, ok := litestream.BoolQueryValue(query, "key") |
| 539 | if ok { |
| 540 | t.Error("BoolQueryValue with missing key should not be ok") |
| 541 | } |
| 542 | }) |
| 543 | |
| 544 | t.Run("Multiple keys", func(t *testing.T) { |
| 545 | query := make(map[string][]string) |
| 546 | query["key2"] = []string{"true"} |
| 547 | value, ok := litestream.BoolQueryValue(query, "key1", "key2") |
| 548 | if !ok { |
| 549 | t.Error("BoolQueryValue should find second key") |
| 550 | } |
| 551 | if !value { |
| 552 | t.Error("BoolQueryValue should return true for second key") |
| 553 | } |
| 554 | }) |
| 555 | |
| 556 | t.Run("Nil query", func(t *testing.T) { |
| 557 | _, ok := litestream.BoolQueryValue(nil, "key") |
| 558 | if ok { |
| 559 | t.Error("BoolQueryValue with nil query should not be ok") |
| 560 | } |
| 561 | }) |
| 562 | |
| 563 | t.Run("Invalid value returns false with ok", func(t *testing.T) { |
| 564 | query := make(map[string][]string) |
nothing calls this directly
no test coverage detected