Skip to content

Commit

Permalink
feat(tests): added test for plugin installation
Browse files Browse the repository at this point in the history
  • Loading branch information
StanGirard committed Apr 9, 2023
1 parent 19f46bb commit ef17889
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ require (
github.com/hashicorp/go-hclog v1.5.0
github.com/hashicorp/go-plugin v1.4.9
github.com/mitchellh/go-homedir v1.1.0
github.com/stretchr/testify v1.7.2
golang.org/x/oauth2 v0.7.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/crypto v0.8.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.7.0 // indirect
Expand Down
56 changes: 56 additions & 0 deletions plugins/commons/pluginUsage_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package commons

import (
"os"
"runtime"
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

func TestInstallPath(t *testing.T) {
p := &Plugin{
Source: "github.com/owner/repo",
Version: "1.0.0",
Name: "test",
}

expectedPath := strings.Join([]string{"github.com/owner/repo", "1.0.0", "yatas-test"}, string(os.PathSeparator))
assert.Equal(t, expectedPath, p.InstallPath())
}

func TestTagName(t *testing.T) {
p := &Plugin{
Version: "latest",
}
assert.Equal(t, "latest", p.TagName())

p.Version = "1.0.0"
assert.Equal(t, "v1.0.0", p.TagName())
}

func TestAssetName(t *testing.T) {
p := &Plugin{
Name: "test",
}

expectedName := strings.Join([]string{"yatas-test", runtime.GOOS, runtime.GOARCH}, "_") + ".zip"
assert.Equal(t, expectedName, p.AssetName())
}

func TestValidate(t *testing.T) {
p := &Plugin{
Name: "test",
Version: "1.0.0",
Source: "github.com/owner/repo",
Type: "checks",
}

err := p.Validate()
assert.Nil(t, err)

p.Type = "invalid_type"
err = p.Validate()
assert.NotNil(t, err)
}

0 comments on commit ef17889

Please sign in to comment.