MCPcopy
hub / github.com/cli/cli / TestCredentialPatternFromGitURL

Function TestCredentialPatternFromGitURL

git/client_test.go:2041–2075  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2039}
2040
2041func 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
2077func TestCredentialPatternFromHost(t *testing.T) {
2078 tests := []struct {

Callers

nothing calls this directly

Calls 3

EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected