Skip to content

Commit 714df34

Browse files
authored
test: add tests for the version command (#15)
1 parent f7b1a8c commit 714df34

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

pkg/cmd/version/version_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package version
2+
3+
import "testing"
4+
5+
func TestFormat(t *testing.T) {
6+
expects := "linkctl version 1.4.0\nhttps://github.com/space-code/linkctl/releases/tag/v1.4.0\n"
7+
if got := Format("1.4.0"); got != expects {
8+
t.Errorf("Format() = %q, wants %q", got, expects)
9+
}
10+
}
11+
12+
func TestChangelogURL(t *testing.T) {
13+
tag := "0.3.2"
14+
url := "https://github.com/space-code/linkctl/releases/tag/v0.3.2"
15+
result := changelogURL(tag)
16+
if result != url {
17+
t.Errorf("expected %s to create url %s but got %s", tag, url, result)
18+
}
19+
20+
tag = "v0.3.2"
21+
url = "https://github.com/space-code/linkctl/releases/tag/v0.3.2"
22+
result = changelogURL(tag)
23+
if result != url {
24+
t.Errorf("expected %s to create url %s but got %s", tag, url, result)
25+
}
26+
27+
tag = "0.3.2-pre.1"
28+
url = "https://github.com/space-code/linkctl/releases/tag/v0.3.2-pre.1"
29+
result = changelogURL(tag)
30+
if result != url {
31+
t.Errorf("expected %s to create url %s but got %s", tag, url, result)
32+
}
33+
34+
tag = "0.3.5-90-gdd3f0e0"
35+
url = "https://github.com/space-code/linkctl/releases/latest"
36+
result = changelogURL(tag)
37+
if result != url {
38+
t.Errorf("expected %s to create url %s but got %s", tag, url, result)
39+
}
40+
41+
tag = "deadbeef"
42+
url = "https://github.com/space-code/linkctl/releases/latest"
43+
result = changelogURL(tag)
44+
if result != url {
45+
t.Errorf("expected %s to create url %s but got %s", tag, url, result)
46+
}
47+
}

0 commit comments

Comments
 (0)