TestValidate checks various scenarios for the Validate function
(t *testing.T)
| 608 | |
| 609 | // TestValidate checks various scenarios for the Validate function |
| 610 | func TestValidate(t *testing.T) { |
| 611 | testCases := []struct { |
| 612 | name string |
| 613 | input string |
| 614 | expect error |
| 615 | }{ |
| 616 | {"Valid UUID", "123e4567-e89b-12d3-a456-426655440000", nil}, |
| 617 | {"Valid UUID with URN", "urn:uuid:123e4567-e89b-12d3-a456-426655440000", nil}, |
| 618 | {"Valid UUID with Braces", "{123e4567-e89b-12d3-a456-426655440000}", nil}, |
| 619 | {"Valid UUID No Hyphens", "123e4567e89b12d3a456426655440000", nil}, |
| 620 | {"Invalid UUID", "invalid-uuid", errors.New("invalid UUID length: 12")}, |
| 621 | {"Invalid Length", "123", fmt.Errorf("invalid UUID length: %d", len("123"))}, |
| 622 | {"Invalid URN Prefix", "urn:test:123e4567-e89b-12d3-a456-426655440000", fmt.Errorf("invalid urn prefix: %q", "urn:test:")}, |
| 623 | {"Invalid Brackets", "[123e4567-e89b-12d3-a456-426655440000]", fmt.Errorf("invalid bracketed UUID format")}, |
| 624 | {"Invalid UUID Format", "12345678gabc1234abcd1234abcd1234", fmt.Errorf("invalid UUID format")}, |
| 625 | } |
| 626 | |
| 627 | for _, tc := range testCases { |
| 628 | t.Run(tc.name, func(t *testing.T) { |
| 629 | err := Validate(tc.input) |
| 630 | if (err != nil) != (tc.expect != nil) || (err != nil && err.Error() != tc.expect.Error()) { |
| 631 | t.Errorf("Validate(%q) = %v, want %v", tc.input, err, tc.expect) |
| 632 | } |
| 633 | }) |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | var asString = "f47ac10b-58cc-0372-8567-0e02b2c3d479" |
| 638 | var asBytes = []byte(asString) |