diff --git a/pkg/cmd/version/version_test.go b/pkg/cmd/version/version_test.go new file mode 100644 index 0000000..0bb54a2 --- /dev/null +++ b/pkg/cmd/version/version_test.go @@ -0,0 +1,47 @@ +package version + +import "testing" + +func TestFormat(t *testing.T) { + expects := "linkctl version 1.4.0\nhttps://github.com/space-code/linkctl/releases/tag/v1.4.0\n" + if got := Format("1.4.0"); got != expects { + t.Errorf("Format() = %q, wants %q", got, expects) + } +} + +func TestChangelogURL(t *testing.T) { + tag := "0.3.2" + url := "https://github.com/space-code/linkctl/releases/tag/v0.3.2" + result := changelogURL(tag) + if result != url { + t.Errorf("expected %s to create url %s but got %s", tag, url, result) + } + + tag = "v0.3.2" + url = "https://github.com/space-code/linkctl/releases/tag/v0.3.2" + result = changelogURL(tag) + if result != url { + t.Errorf("expected %s to create url %s but got %s", tag, url, result) + } + + tag = "0.3.2-pre.1" + url = "https://github.com/space-code/linkctl/releases/tag/v0.3.2-pre.1" + result = changelogURL(tag) + if result != url { + t.Errorf("expected %s to create url %s but got %s", tag, url, result) + } + + tag = "0.3.5-90-gdd3f0e0" + url = "https://github.com/space-code/linkctl/releases/latest" + result = changelogURL(tag) + if result != url { + t.Errorf("expected %s to create url %s but got %s", tag, url, result) + } + + tag = "deadbeef" + url = "https://github.com/space-code/linkctl/releases/latest" + result = changelogURL(tag) + if result != url { + t.Errorf("expected %s to create url %s but got %s", tag, url, result) + } +}