(t *testing.T)
| 698 | } |
| 699 | |
| 700 | func TestValidateAPIIdentifier(t *testing.T) { |
| 701 | t.Parallel() |
| 702 | |
| 703 | tests := []struct { |
| 704 | name string |
| 705 | identifier string |
| 706 | wantErr bool |
| 707 | }{ |
| 708 | { |
| 709 | name: "valid http URL", |
| 710 | identifier: "http://example.com/api", |
| 711 | wantErr: false, |
| 712 | }, |
| 713 | { |
| 714 | name: "valid https URL", |
| 715 | identifier: "https://my-api.example.com", |
| 716 | wantErr: false, |
| 717 | }, |
| 718 | { |
| 719 | // ParseRequestURI succeeds for valid URLs regardless of length, so |
| 720 | // the err==nil branch returns nil before the length check is reached. |
| 721 | name: "valid URL exactly 24 characters", |
| 722 | identifier: "https://foo.example.com/", |
| 723 | wantErr: false, |
| 724 | }, |
| 725 | { |
| 726 | // Both conditions must be true to trigger an error: the string must |
| 727 | // fail ParseRequestURI AND be exactly 24 characters long. A plain |
| 728 | // 24-character ID (no scheme) satisfies both. |
| 729 | name: "24-character non-URL identifier", |
| 730 | identifier: "abc123def456ghi789jkl012", |
| 731 | wantErr: true, |
| 732 | }, |
| 733 | } |
| 734 | |
| 735 | for _, tc := range tests { |
| 736 | t.Run(tc.name, func(t *testing.T) { |
| 737 | t.Parallel() |
| 738 | err := validateAPIIdentifier(tc.identifier) |
| 739 | if tc.wantErr { |
| 740 | assert.Error(t, err) |
| 741 | } else { |
| 742 | assert.NoError(t, err) |
| 743 | } |
| 744 | }) |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | // -- createQuickstartApp happy-path --. |
| 749 |
nothing calls this directly
no test coverage detected