Skip to content

Commit

Permalink
Add doctl tool to get command
Browse files Browse the repository at this point in the history
No ARM support at present, tested on Linux with WSL2 and
with Windows in Git Bash.

Closes: #179

Co-authored-by: Kyle Brennan <[email protected]>

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Aug 19, 2020
1 parent 25a1f7b commit 612c2af
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 51 deletions.
115 changes: 64 additions & 51 deletions pkg/get/get_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
package get

import "testing"
import (
"fmt"
"testing"
)

const faasCLIVersion = "0.12.8"
const arch64bit = "x86_64"
const archARM7 = "armv7l"

type test struct {
os string
arch string
version string
url string
}

func getTool(name string, tools []Tool) *Tool {
var tool *Tool
for _, target := range tools {
if name == target.Name {
tool = &target
break
}
}
return tool
}

func Test_DownloadDarwin(t *testing.T) {
tools := MakeTools()
Expand Down Expand Up @@ -227,13 +249,6 @@ func Test_DownloadKubeseal(t *testing.T) {
}
}

type test struct {
os string
arch string
version string
url string
}

tests := []test{
{os: "mingw64_nt-10.0-18362",
arch: arch64bit,
Expand Down Expand Up @@ -279,13 +294,6 @@ func Test_DownloadKind(t *testing.T) {
}
}

type test struct {
os string
arch string
version string
url string
}

tests := []test{
{os: "mingw64_nt-10.0-18362",
arch: arch64bit,
Expand Down Expand Up @@ -331,13 +339,6 @@ func Test_DownloadK3d(t *testing.T) {
}
}

type test struct {
os string
arch string
version string
url string
}

tests := []test{
{os: "mingw64_nt-10.0-18362",
arch: arch64bit,
Expand Down Expand Up @@ -383,13 +384,6 @@ func Test_DownloadK3sup(t *testing.T) {
}
}

type test struct {
os string
arch string
version string
url string
}

tests := []test{
{os: "mingw64_nt-10.0-18362",
arch: arch64bit,
Expand Down Expand Up @@ -435,13 +429,6 @@ func Test_DownloadInletsctl(t *testing.T) {
}
}

type test struct {
os string
arch string
version string
url string
}

tests := []test{
{os: "mingw64_nt-10.0-18362",
arch: arch64bit,
Expand Down Expand Up @@ -487,13 +474,6 @@ func Test_DownloadKubebuilder(t *testing.T) {
}
}

type test struct {
os string
arch string
version string
url string
}

tests := []test{
{os: "darwin",
arch: arch64bit,
Expand Down Expand Up @@ -532,13 +512,6 @@ func Test_DownloadKustomize(t *testing.T) {
}
}

type test struct {
os string
arch string
version string
url string
}

ver := "kustomize/v3.8.1"

tests := []test{
Expand All @@ -565,7 +538,47 @@ func Test_DownloadKustomize(t *testing.T) {
t.Fatal(err)
}
if got != tc.url {
t.Fatalf("want: %s, got: %s", tc.url, got)
t.Errorf("want: %s, got: %s", tc.url, got)
}
}
}

func Test_DownloadDigitalOcean(t *testing.T) {
tools := MakeTools()
name := "doctl"

tool := getTool(name, tools)

const toolVersion = "1.46.0"
const urlTemplate = "https://github.com/digitalocean/doctl/releases/download/v1.46.0/doctl-1.46.0-%s-%s.%s"

tests := []test{
{os: "mingw64_nt-10.0-18362",
arch: arch64bit,
version: toolVersion,
url: fmt.Sprintf(urlTemplate, "windows", "amd64", "zip")},
{os: "linux",
arch: arch64bit,
version: toolVersion,
url: fmt.Sprintf(urlTemplate, "linux", "amd64", "tar.gz")},
{os: "darwin",
arch: arch64bit,
version: toolVersion,
url: fmt.Sprintf(urlTemplate, "darwin", "amd64", "tar.gz")},
// this asserts that we can build a URL for ARM processors, but no asset exists and will yield a 404
{os: "linux",
arch: archARM7,
version: toolVersion,
url: fmt.Sprintf(urlTemplate, "linux", "", "tar.gz")},
}

for _, tc := range tests {
got, err := tool.GetURL(tc.os, tc.arch, tc.version)
if err != nil {
t.Fatal(err)
}
if got != tc.url {
t.Errorf("want: %s, got: %s", tc.url, got)
}
}
}
31 changes: 31 additions & 0 deletions pkg/get/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,36 @@ https://github.com/inlets/inletsctl/releases/download/{{.Version}}/{{$fileName}}
https://github.com/{{.Owner}}/{{.Repo}}/releases/download/{{.Version}}/{{.Name}}_v3.8.1_{{$osStr}}.tar.gz`,
})

tools = append(tools,
Tool{
Owner: "digitalocean",
Repo: "doctl",
Name: "doctl",
Version: "1.46.0",
URLTemplate: `
{{$osStr := ""}}
{{ if HasPrefix .OS "ming" -}}
{{$osStr = "windows"}}
{{- else if eq .OS "linux" -}}
{{$osStr = "linux"}}
{{- else if eq .OS "darwin" -}}
{{$osStr = "darwin"}}
{{- end -}}
{{$archStr := ""}}
{{- if eq .Arch "x86_64" -}}
{{$archStr = "amd64"}}
{{- end -}}
{{$archiveStr := ""}}
{{ if HasPrefix .OS "ming" -}}
{{$archiveStr = "zip"}}
{{- else -}}
{{$archiveStr = "tar.gz"}}
{{- end -}}
https://github.com/digitalocean/doctl/releases/download/v{{.Version}}/doctl-{{.Version}}-{{$osStr}}-{{$archStr}}.{{$archiveStr}}`,
})

return tools
}

0 comments on commit 612c2af

Please sign in to comment.