-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathutil_test.go
More file actions
96 lines (84 loc) · 3.55 KB
/
Copy pathutil_test.go
File metadata and controls
96 lines (84 loc) · 3.55 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import "testing"
func TestParseModuleCommit(t *testing.T) {
for i, tc := range []struct {
str string
commit string
isSha bool
}{
{"v16.2.1+incompatible", "v16.2.1", false},
{"v0.0.0-20171204204709-577dee27f20d", "577dee27f20d", true},
{"v1.0.0", "v1.0.0", false},
{"v1.0.0-rc1", "v1.0.0-rc1", false},
{"v0.4.15-0.20190919025122-fc70bd9a86b5", "fc70bd9a86b5", true},
} {
commit, isSha := getCommitOrVersion(tc.str)
if commit != tc.commit {
t.Fatalf("[%d] unexpected commit %q, expected %q", i, commit, tc.commit)
}
if isSha != tc.isSha {
t.Fatalf("[%d] unexpected sha %t, expected %t", i, isSha, tc.isSha)
}
}
}
func TestGetGitURL(t *testing.T) {
for _, tc := range []struct {
name string
git string
}{
{"github.com/docker/distribution", "https://github.com/docker/distribution"},
{"sigs.k8s.io/yaml", "https://github.com/kubernetes-sigs/yaml"},
{"sigs.k8s.io/yaml/v2", "https://github.com/kubernetes-sigs/yaml"},
{"k8s.io/utils", "https://github.com/kubernetes/utils"},
{"k8s.io/utils/v8", "https://github.com/kubernetes/utils"},
{"k8s.io/client-go", "https://github.com/kubernetes/client-go"},
{"github.com/someorg/somerepo/v2", "https://github.com/someorg/somerepo"},
{"github.com/someorg/somerepo/unnecessarysubmod", "https://github.com/someorg/somerepo"},
{"github.com/invalid", ""},
//{"gopkg.in/src-d/go-git.v4", "https://github.com/src-d/go-git"},
//{"golang.org/x/tools", "https://github.com/golang/tools"},
//{"golang.org/x/sync", "https://github.com/golang/sync"},
} {
git := getGitURL(tc.name)
if git != tc.git {
t.Errorf("[%s] unexpected git url %q, expected %q", tc.name, git, tc.git)
}
}
}
func TestReleaseNote(t *testing.T) {
for i, tc := range []struct {
body string
note string
}{
{"", ""},
{"not a release note", ""},
{"```release-note\nJust a release note\n```", "Just a release note"},
{"``` release-note\nJust a release note\n```", "Just a release note"},
{"``` release-note\nJust a release note\n```\n", "Just a release note"},
{"``` release-note\r\nJust a release note\r\n```", "Just a release note"},
{"``` release-note\r\nJust a release note\r\n```\r\n", "Just a release note"},
{"``` release-note\r\nJust a\r\nrelease note\r\n```", "Just a\nrelease note"},
{"Pull request body\n\n```release-note\nMore than a\n**`release note`**\n```", "More than a\n**`release note`**"},
{"Pull request body\n```release-note\nThe release note\n```\nNot Actually the end", "The release note"},
{"Poorly formatted```release-note\nThe release note\n```\n", ""},
{"Two blocks\n```release-note\nThe release note\n```\nAnd\n\n```something-else\ncode and more code\n```", "The release note"},
{"Two release notes\n```release-note\nThe first release note\n```\nAnd\n\n```release-note\nThe second release note\n```", "The first release note"},
} {
note := getReleaseNote(tc.body)
if note != tc.note {
t.Errorf("[%d] unexpected release note\n\t%q\nexpected\n\t%q", i, note, tc.note)
}
}
}