From 9952e0968ee7d2a9d5202798341cd140bf08f667 Mon Sep 17 00:00:00 2001 From: Tiago Ilieve Date: Sat, 7 Sep 2024 11:22:28 -0300 Subject: [PATCH] Remove redundant '/releases' URL suffix --- tools/tables.go | 18 ++++++------- tools/tools.go | 2 ++ tools/tools_test.go | 62 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 9 deletions(-) diff --git a/tools/tables.go b/tools/tables.go index 8291225..ff23853 100644 --- a/tools/tables.go +++ b/tools/tables.go @@ -176,13 +176,13 @@ var OS = map[string]map[string]map[string]string{ } var URL = map[string]string{ - Bat: "https://github.com/sharkdp/bat/releases", - Bottom: "https://github.com/ClementTsang/bottom/releases", - Cloudflared: "https://github.com/cloudflare/cloudflared/releases", - Flyctl: "https://github.com/superfly/flyctl/releases", - K9s: "https://github.com/derailed/k9s/releases", - Kubectx: "https://github.com/ahmetb/kubectx/releases", - UPX: "https://github.com/upx/upx/releases", - Xh: "https://github.com/ducaale/xh/releases", - Yj: "https://github.com/sclevine/yj/releases", + Bat: "https://github.com/sharkdp/bat", + Bottom: "https://github.com/ClementTsang/bottom", + Cloudflared: "https://github.com/cloudflare/cloudflared", + Flyctl: "https://github.com/superfly/flyctl", + K9s: "https://github.com/derailed/k9s", + Kubectx: "https://github.com/ahmetb/kubectx", + UPX: "https://github.com/upx/upx", + Xh: "https://github.com/ducaale/xh", + Yj: "https://github.com/sclevine/yj", } diff --git a/tools/tools.go b/tools/tools.go index 4961a6e..43857c7 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -194,6 +194,8 @@ func (t *Tool) SetURL() error { return fmt.Errorf("no url defined for: %v", t.Name) } + t.URL += "/releases" + return nil } diff --git a/tools/tools_test.go b/tools/tools_test.go index 7cfea58..d2e1ab6 100644 --- a/tools/tools_test.go +++ b/tools/tools_test.go @@ -28,3 +28,65 @@ func (s *ToolsTestSuite) TestDownload() { s.Contains(err.Error(), "404 Not Found") }) } + +func (s *ToolsTestSuite) TestSetURL() { + s.Run("should set URL correctly for known tools", func() { + testCases := []struct { + name string + url string + }{ + { + name: Bat, + url: "https://github.com/sharkdp/bat/releases", + }, + { + name: Bottom, + url: "https://github.com/ClementTsang/bottom/releases", + }, + { + name: Cloudflared, + url: "https://github.com/cloudflare/cloudflared/releases", + }, + { + name: Flyctl, + url: "https://github.com/superfly/flyctl/releases", + }, + { + name: K9s, + url: "https://github.com/derailed/k9s/releases", + }, + { + name: Kubectx, + url: "https://github.com/ahmetb/kubectx/releases", + }, + { + name: UPX, + url: "https://github.com/upx/upx/releases", + }, + { + name: Xh, + url: "https://github.com/ducaale/xh/releases", + }, + { + name: Yj, + url: "https://github.com/sclevine/yj/releases", + }, + } + + for _, tc := range testCases { + tool := Tool{Name: tc.name} + err := tool.SetURL() + s.NoError(err) + s.Equal(tc.url, tool.URL) + } + }) + + s.Run("should return error for unknown tool", func() { + tool := Tool{ + Name: "unknown_tool", + } + err := tool.SetURL() + s.Error(err) + s.Contains(err.Error(), "no url defined for: unknown_tool") + }) +}