(t *testing.T)
| 2039 | } |
| 2040 | |
| 2041 | func TestCredentialPatternFromGitURL(t *testing.T) { |
| 2042 | tests := []struct { |
| 2043 | name string |
| 2044 | gitURL string |
| 2045 | wantErr bool |
| 2046 | wantCredentialPattern CredentialPattern |
| 2047 | }{ |
| 2048 | { |
| 2049 | name: "Given a well formed gitURL, it returns the corresponding CredentialPattern", |
| 2050 | gitURL: "https://github.com/OWNER/REPO.git", |
| 2051 | wantCredentialPattern: CredentialPattern{ |
| 2052 | pattern: "https://github.com", |
| 2053 | allMatching: false, |
| 2054 | }, |
| 2055 | }, |
| 2056 | { |
| 2057 | name: "Given a malformed gitURL, it returns an error", |
| 2058 | // This pattern is copied from the tests in ParseURL |
| 2059 | // Unexpectedly, a non URL-like string did not error in ParseURL |
| 2060 | gitURL: "ssh://git@[/tmp/git-repo", |
| 2061 | wantErr: true, |
| 2062 | }, |
| 2063 | } |
| 2064 | for _, tt := range tests { |
| 2065 | t.Run(tt.name, func(t *testing.T) { |
| 2066 | credentialPattern, err := CredentialPatternFromGitURL(tt.gitURL) |
| 2067 | if tt.wantErr { |
| 2068 | assert.ErrorContains(t, err, "failed to parse remote URL") |
| 2069 | } else { |
| 2070 | assert.NoError(t, err) |
| 2071 | assert.Equal(t, tt.wantCredentialPattern, credentialPattern) |
| 2072 | } |
| 2073 | }) |
| 2074 | } |
| 2075 | } |
| 2076 | |
| 2077 | func TestCredentialPatternFromHost(t *testing.T) { |
| 2078 | tests := []struct { |
nothing calls this directly
no test coverage detected