Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add integration tests for krew install with --archive and --manifes…
…t options (#245)

* Add test cases for `krew install` with --archive and --manifest options

* Improve formatting

* ReplaceAll was added in go 1.12, but krew uses 1.11

* Rename test plugin from `test-foo` to `foo`

* Use wildcard platform selector in test data

* Add windows version of the test plugin for testing on windows
  • Loading branch information
corneliusweig authored and k8s-ci-robot committed Jul 9, 2019
1 parent 2dab1a1 commit 7b2c944
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 1 deletion.
50 changes: 49 additions & 1 deletion integration_test/install_test.go
Expand Up @@ -14,7 +14,16 @@

package integrationtest

import "testing"
import (
"path/filepath"
"testing"

"sigs.k8s.io/krew/pkg/constants"
)

const (
fooPlugin = "foo"
)

func TestKrewInstall(t *testing.T) {
skipShort(t)
Expand All @@ -25,3 +34,42 @@ func TestKrewInstall(t *testing.T) {
test.WithIndex().Krew("install", validPlugin).RunOrFailOutput()
test.AssertExecutableInPATH("kubectl-" + validPlugin)
}

func TestKrewInstall_Manifest(t *testing.T) {
skipShort(t)

test, cleanup := NewTest(t)
defer cleanup()

test.Krew("install",
"--manifest", filepath.Join("testdata", validPlugin+constants.ManifestExtension)).
RunOrFail()
test.AssertExecutableInPATH("kubectl-" + validPlugin)
}

func TestKrewInstall_ManifestAndArchive(t *testing.T) {
skipShort(t)

test, cleanup := NewTest(t)
defer cleanup()

test.Krew("install",
"--manifest", filepath.Join("testdata", fooPlugin+constants.ManifestExtension),
"--archive", filepath.Join("testdata", fooPlugin+".tar.gz")).
RunOrFail()
test.AssertExecutableInPATH("kubectl-" + fooPlugin)
}

func TestKrewInstall_OnlyArchiveFails(t *testing.T) {
skipShort(t)

test, cleanup := NewTest(t)
defer cleanup()

err := test.Krew("install",
"--archive", filepath.Join("testdata", fooPlugin+".tar.gz")).
Run()
if err == nil {
t.Errorf("Expected install to fail but was successful")
}
}
Binary file added integration_test/testdata/foo.tar.gz
Binary file not shown.
28 changes: 28 additions & 0 deletions integration_test/testdata/foo.yaml
@@ -0,0 +1,28 @@
apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
name: foo
spec:
version: "v0.1.0"
shortDescription: A valid plugin for integration tests
platforms:
- uri: https://foo.bar/foo.tar.gz
sha256: 354bad230cdd0966fc8c919476c4e6c7f2078b04a6ff7dead6a811cdc101d31e
bin: foo.sh
files:
- from: ./foo.sh
to: "."
selector:
matchExpressions:
- key: os
operator: In
values: ["darwin", "linux"]
- uri: https://foo.bar/foo.tar.gz
sha256: 354bad230cdd0966fc8c919476c4e6c7f2078b04a6ff7dead6a811cdc101d31e
bin: foo.bat
files:
- from: ./foo.bat
to: "."
selector:
matchLabels:
os: windows
28 changes: 28 additions & 0 deletions integration_test/testdata/konfig.yaml
@@ -0,0 +1,28 @@
apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
name: konfig
spec:
version: "v0.2.0"
shortDescription: a plugin in central index with small size
platforms:
- uri: https://github.com/corneliusweig/konfig/releases/download/v0.2.0/bundle.tar.gz
sha256: 7dc7b884ca92e3c9b39f905cc11bcf31e79b9c929741a4383d9ff61414101962
bin: konfig-krew
files:
- from: ./konfig-krew
to: "."
selector:
matchExpressions:
- key: os
operator: In
values: ["darwin", "linux"]
- uri: https://github.com/corneliusweig/konfig/releases/download/v0.2.0/bundle.tar.gz
sha256: 7dc7b884ca92e3c9b39f905cc11bcf31e79b9c929741a4383d9ff61414101962
bin: konfig-krew.exe
files:
- from: ./konfig-krew
to: konfig-krew.exe
selector:
matchLabels:
os: windows

0 comments on commit 7b2c944

Please sign in to comment.