1
0
mirror of https://github.com/helm/chart-testing.git synced 2026-02-05 09:45:14 +01:00
Files
chart-testing/pkg/tool/account_test.go
Reinhard Nägele e731d947fb Consider username and password in repo urls (#162)
Signed-off-by: Reinhard Naegele <unguiculus@gmail.com>
2019-07-09 07:24:17 +02:00

37 lines
1.3 KiB
Go

package tool
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseOutGitDomain(t *testing.T) {
var testDataSlice = []struct {
name string
repoUrl string
expected string
err error
}{
{"GitHub SSH", "git@github.com:foo/bar", "github.com", nil},
{"GitHub HTTPS", "https://github.com/foo/bar", "github.com", nil},
{"GitHub HTTPS with username/password", "https://foo:token@github.com/foo/bar", "github.com", nil},
{"Gitlab SSH", "git@gitlab.com:foo/bar", "gitlab.com", nil},
{"Gitlab HTTPS", "https://gitlab.com/foo/bar", "gitlab.com", nil},
{"Gitlab HTTPS with username/password", "https://gitlab-ci-token:password@gitlab.com/foo/bar", "gitlab.com", nil},
{"Bitbucket SSH", "git@bitbucket.com:foo/bar", "bitbucket.com", nil},
{"Bitbucket HTTPS", "https://bitbucket.com/foo/bar", "bitbucket.com", nil},
{"Bitbucket HTTPS with username/password", "https://user:pass@bitbucket.com/foo/bar", "bitbucket.com", nil},
{"Invalid", "foo/bar", "", fmt.Errorf("Could not parse git repository domain for 'foo/bar'")},
}
for _, testData := range testDataSlice {
t.Run(testData.name, func(t *testing.T) {
actual, err := parseOutGitRepoDomain(testData.repoUrl)
assert.Equal(t, err, testData.err)
assert.Equal(t, testData.expected, actual)
})
}
}