-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ce275a
commit 256b5f3
Showing
3 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package consul | ||
|
||
import ( | ||
"fmt" | ||
"github.com/Masterminds/semver" | ||
kpkgerr "github.com/spachava753/kpkg/pkg/error" | ||
"github.com/spachava753/kpkg/pkg/tool" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
type consulTool struct { | ||
arch, | ||
os string | ||
tool.GithubReleaseTool | ||
} | ||
|
||
func (l consulTool) Extract(artifactPath, _ string) (string, error) { | ||
binaryPath := filepath.Join(artifactPath, l.Name()) | ||
binaryPathInfo, err := os.Stat(binaryPath) | ||
if err != nil { | ||
return "", err | ||
} | ||
if binaryPathInfo.IsDir() { | ||
return "", fmt.Errorf("could not extract binary: %w", fmt.Errorf("path %s is not a directory", binaryPathInfo)) | ||
} | ||
|
||
return binaryPath, err | ||
} | ||
|
||
func (l consulTool) Name() string { | ||
return "consul" | ||
} | ||
|
||
func (l consulTool) ShortDesc() string { | ||
return "Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure" | ||
} | ||
|
||
func (l consulTool) LongDesc() string { | ||
return "Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure" | ||
} | ||
|
||
func (l consulTool) MakeUrl(version string) (string, error) { | ||
v, err := semver.NewVersion(version) | ||
if err != nil { | ||
return "", err | ||
} | ||
version = v.String() | ||
switch { | ||
case l.os == "darwin" && l.arch == "amd64", | ||
l.os == "windows" && l.arch == "386", | ||
l.os == "windows" && l.arch == "amd64", | ||
l.os == "linux" && l.arch == "amd64", | ||
l.os == "linux" && l.arch == "arm64", | ||
l.os == "linux" && l.arch == "arm", | ||
l.os == "linux" && l.arch == "386", | ||
l.os == "freebsd" && l.arch == "amd64", | ||
l.os == "freebsd" && l.arch == "arm", | ||
l.os == "freebsd" && l.arch == "386", | ||
l.os == "openbsd" && l.arch == "amd64", | ||
l.os == "openbsd" && l.arch == "386", | ||
l.os == "solaris" && l.arch == "amd64": | ||
default: | ||
return "", &kpkgerr.UnsupportedRuntimeErr{Binary: l.Name()} | ||
} | ||
url := fmt.Sprintf("https://releases.hashicorp.com/consul/%s/consul_%s_%s_%s.zip", version, version, l.os, l.arch) | ||
return url, nil | ||
} | ||
|
||
func MakeBinary(os, arch string) tool.Binary { | ||
return consulTool{ | ||
arch: arch, | ||
os: os, | ||
GithubReleaseTool: tool.MakeGithubReleaseTool("hashicorp", "consul", 20), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package consul | ||
|
||
import ( | ||
"runtime" | ||
"testing" | ||
) | ||
|
||
func TestConsulTool_Versions(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
want []string | ||
homeDir string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "List versions", | ||
want: nil, | ||
homeDir: t.TempDir(), | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
l := MakeBinary(runtime.GOOS, runtime.GOARCH) | ||
_, err := l.Versions() | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("Versions() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
}) | ||
} | ||
} |