|
1 | 1 | package tool |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "github.com/stretchr/testify/assert" |
| 4 | + "fmt" |
5 | 5 | "testing" |
| 6 | + |
| 7 | + "github.com/stretchr/testify/assert" |
6 | 8 | ) |
7 | 9 |
|
8 | 10 | func TestParseOutGitDomain(t *testing.T) { |
9 | 11 | var testDataSlice = []struct { |
10 | 12 | name string |
11 | 13 | repoUrl string |
12 | 14 | expected string |
| 15 | + err error |
13 | 16 | }{ |
14 | | - { "GitHub SSH", "[email protected]:foo/bar", "github.com"}, |
15 | | - {"GitHub HTTPS", "https://github.com/foo/bar", "github.com"}, |
16 | | - { "Gitlab SSH", "[email protected]:foo/bar", "gitlab.com"}, |
17 | | - {"Gitlab HTTPS", "https://gitlab.com/foo/bar", "gitlab.com"}, |
18 | | - { "Bitbucket SSH", "[email protected]:foo/bar", "bitbucket.com"}, |
19 | | - {"Bitbucket HTTPS", "https://bitbucket.com/foo/bar", "bitbucket.com"}, |
| 17 | + { "GitHub SSH", "[email protected]:foo/bar", "github.com", nil}, |
| 18 | + {"GitHub HTTPS", "https://github.com/foo/bar", "github.com", nil}, |
| 19 | + { "Gitlab SSH", "[email protected]:foo/bar", "gitlab.com", nil}, |
| 20 | + {"Gitlab HTTPS", "https://gitlab.com/foo/bar", "gitlab.com", nil}, |
| 21 | + { "Bitbucket SSH", "[email protected]:foo/bar", "bitbucket.com", nil}, |
| 22 | + {"Bitbucket HTTPS", "https://bitbucket.com/foo/bar", "bitbucket.com", nil}, |
| 23 | + {"Invalid", "foo/bar", "", fmt.Errorf("Could not parse git repository domain for 'foo/bar'")}, |
20 | 24 | } |
21 | 25 |
|
22 | 26 | for _, testData := range testDataSlice { |
23 | 27 | t.Run(testData.name, func(t *testing.T) { |
24 | | - actual := parseOutGitRepoDomain(testData.repoUrl) |
| 28 | + actual, err := parseOutGitRepoDomain(testData.repoUrl) |
| 29 | + assert.Equal(t, err, testData.err) |
25 | 30 | assert.Equal(t, testData.expected, actual) |
26 | 31 | }) |
27 | 32 | } |
|
0 commit comments