1
0
mirror of https://github.com/alexellis/arkade.git synced 2022-05-07 18:22:49 +03:00
Files
arkade-kubernetes/pkg/get/get_test.go
Alex Ellis (OpenFaaS Ltd) 4efd6d7869 Add "get" command
The get command downloads tools from GitHub release pages
and from custom URLs using a go template to define the
URL and filename according to OS and architecture.

Tested with unit tests and with the two initial apps: faas-cli
and kubectl.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
2020-06-16 10:25:05 +01:00

133 lines
2.7 KiB
Go

package get
import "testing"
const faasCLIVersion = "0.12.4"
const arch64bit = "x86_64"
func Test_DownloadDarwin(t *testing.T) {
tools := MakeTools()
name := "faas-cli"
var tool *Tool
for _, target := range tools {
if name == target.Name {
tool = &target
break
}
}
got, err := tool.GetURL("darwin", "", "")
if err != nil {
t.Fatal(err)
}
want := "https://github.com/openfaas/faas-cli/releases/download/" + faasCLIVersion + "/faas-cli-darwin"
if got != want {
t.Fatalf("want: %s, got: %s", want, got)
}
}
func Test_DownloadKubectlDarwin(t *testing.T) {
tools := MakeTools()
name := "kubectl"
var tool *Tool
for _, target := range tools {
if name == target.Name {
tool = &target
break
}
}
got, err := tool.GetURL("darwin", arch64bit, tool.Version)
if err != nil {
t.Fatal(err)
}
want := "https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/darwin/amd64/kubectl"
if got != want {
t.Fatalf("want: %s, got: %s", want, got)
}
}
func Test_DownloadKubectlLinux(t *testing.T) {
tools := MakeTools()
name := "kubectl"
var tool *Tool
for _, target := range tools {
if name == target.Name {
tool = &target
break
}
}
got, err := tool.GetURL("linux", arch64bit, tool.Version)
if err != nil {
t.Fatal(err)
}
want := "https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl"
if got != want {
t.Fatalf("want: %s, got: %s", want, got)
}
}
func Test_DownloadArmhf(t *testing.T) {
tools := MakeTools()
name := "faas-cli"
var tool *Tool
for _, target := range tools {
if name == target.Name {
tool = &target
break
}
}
got, err := tool.GetURL("Linux", "armv7l", "")
if err != nil {
t.Fatal(err)
}
want := "https://github.com/openfaas/faas-cli/releases/download/" + faasCLIVersion + "/faas-cli-armhf"
if got != want {
t.Fatalf("want: %s, got: %s", want, got)
}
}
func Test_DownloadArm64(t *testing.T) {
tools := MakeTools()
name := "faas-cli"
var tool *Tool
for _, target := range tools {
if name == target.Name {
tool = &target
break
}
}
got, err := tool.GetURL("Linux", "aarch64", "")
if err != nil {
t.Fatal(err)
}
want := "https://github.com/openfaas/faas-cli/releases/download/" + faasCLIVersion + "/faas-cli-arm64"
if got != want {
t.Fatalf("want: %s, got: %s", want, got)
}
}
func Test_DownloadWindows(t *testing.T) {
tools := MakeTools()
name := "faas-cli"
var tool *Tool
for _, target := range tools {
if name == target.Name {
tool = &target
break
}
}
got, err := tool.GetURL("mingw64_nt-10.0-18362", arch64bit, "")
if err != nil {
t.Fatal(err)
}
want := "https://github.com/openfaas/faas-cli/releases/download/" + faasCLIVersion + "/faas-cli.exe"
if got != want {
t.Fatalf("want: %s, got: %s", want, got)
}
}