forked from pkallberg/cx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git_test.go
51 lines (47 loc) · 3.48 KB
/
git_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"testing"
)
var prepareGitMatches = []struct {
name string
lhs string
rhs string
shouldMatch bool
}{
{"identical - https", "https://github.com/cloud66/stacks-test.git", "https://github.com/cloud66/stacks-test.git", true},
{"identical - http", "http://github.com/cloud66/stacks-test.git", "http://github.com/cloud66/stacks-test.git", true},
{"identical - git", "git://github.com/cloud66/stacks-test.git", "git://github.com/cloud66/stacks-test.git", true},
{"no .git - https", "https://github.com/cloud66/stacks-test", "git://github.com/cloud66/stacks-test", true},
{"no .git - http", "http://github.com/cloud66/stacks-test", "http://github.com/cloud66/stacks-test", true},
{"asym .git - https", "https://github.com/cloud66/stacks-test.git", "https://github.com/cloud66/stacks-test", true},
{"asym .git - git", "git://github.com/cloud66/stacks-test.git", "git://github.com/cloud66/stacks-test", true},
{"identical - git@", "git@github.com:cloud66/stacks-test.git", "git@github.com:cloud66/stacks-test.git", true},
{"no .git - git@", "git@github.com:cloud66/stacks-test.git", "git@github.com:cloud66/stacks-test", true},
{"http - git", "git://github.com/cloud66/stacks-test.git", "http://github.com/cloud66/stacks-test.git", true},
{"http - git@", "git@github.com:cloud66/stacks-test.git", "http://github.com/cloud66/stacks-test.git", true},
{"git - git@", "git@github.com:cloud66/stacks-test.git", "git://github.com/cloud66/stacks-test.git", true},
{"different domains - git@ - git", "git@bitbucket.com:cloud66/stacks-test.git", "git://github.com/cloud66/stacks-test.git", false},
{"different domains - git - git", "git://bitbucket.com/cloud66/stacks-test.git", "git://github.com/cloud66/stacks-test.git", false},
{"different domains - http - http", "http://bitbucket.com/cloud66/stacks-test.git", "http://github.com/cloud66/stacks-test.git", false},
{"different domains - https - http", "https://bitbucket.com/cloud66/stacks-test.git", "http://github.com/cloud66/stacks-test.git", false},
{"invalid URLs", "this is totally wrong", "yes! absolutely", false},
{"different URLs - http - http", "http://github.com/cloud666/stacks-test.git", "http://github.com/cloud66/stacks-test.git", false},
{"different URLs - git - http", "git://github.com/cloud666/stacks-test.git", "http://github.com/cloud66/stacks-test.git", false},
{"different URLs - @git - http", "git@github.com:cloud666/stacks-test.git", "http://github.com/cloud66/stacks-test.git", false},
{"different URLs - @git - git", "git@github.com:cloud666/stacks-test.git", "git://github.com/cloud66/stacks-test.git", false},
{"Same URL - different users - https - https", "https://a:b@github.com/cloud66/stacks-test.git", "https://x:y@github.com/cloud66/stacks-test.git", true},
{"Same URL - different users - git - https", "git://a:b@github.com/cloud66/stacks-test.git", "https://x:y@github.com/cloud66/stacks-test.git", true},
{"Same URL - different users - git - git@", "git://a:b@github.com/cloud66/stacks-test.git", "git@github.com:cloud66/stacks-test.git", true},
{"identical - allow spaces - https", "https://github.com/cloud66/stacks-test.git ", " https://github.com/cloud66/stacks-test.git", true},
}
func TestAreSameRemotes(t *testing.T) {
for _, m := range prepareGitMatches {
result, err := areSameRemotes(m.lhs, m.rhs)
if err != nil {
t.Errorf("Error %v in %s\n", err, m.name)
}
if result != m.shouldMatch {
t.Errorf("%s failed with with %t. Should have been %t\n", m.name, result, m.shouldMatch)
}
}
}