Skip to content

Commit

Permalink
Remove redundant '/releases' URL suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
myhro committed Sep 7, 2024
1 parent 22a112f commit 9952e09
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 9 deletions.
18 changes: 9 additions & 9 deletions tools/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
2 changes: 2 additions & 0 deletions tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ func (t *Tool) SetURL() error {
return fmt.Errorf("no url defined for: %v", t.Name)
}

t.URL += "/releases"

return nil
}

Expand Down
62 changes: 62 additions & 0 deletions tools/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
}

0 comments on commit 9952e09

Please sign in to comment.