From 7b2c94485b65d9fda7ad6cf78bce7275da03288d Mon Sep 17 00:00:00 2001 From: Cornelius Weig <22861411+corneliusweig@users.noreply.github.com> Date: Tue, 9 Jul 2019 18:48:04 +0200 Subject: [PATCH] Add integration tests for `krew install` with --archive and --manifest 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 --- integration_test/install_test.go | 50 +++++++++++++++++++++++++- integration_test/testdata/foo.tar.gz | Bin 0 -> 199 bytes integration_test/testdata/foo.yaml | 28 +++++++++++++++ integration_test/testdata/konfig.yaml | 28 +++++++++++++++ 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 integration_test/testdata/foo.tar.gz create mode 100644 integration_test/testdata/foo.yaml create mode 100644 integration_test/testdata/konfig.yaml diff --git a/integration_test/install_test.go b/integration_test/install_test.go index a3b3580e..668f602c 100644 --- a/integration_test/install_test.go +++ b/integration_test/install_test.go @@ -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) @@ -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") + } +} diff --git a/integration_test/testdata/foo.tar.gz b/integration_test/testdata/foo.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..c0e61a1ba9cf13826b980e30f86971db77fc8475 GIT binary patch literal 199 zcmb2|=3oE;Cg!)7O_L5g2sm6^`&}fh{9?}r9_Q!UGiJ7K=Qj?0_(we==YPT0Tb;+B z1)p51!LiP*m#I?XeM{06?hw@=e;eghuYNC6dB(k@@Y2m`UTX3_ZhOn$+0OZ|d3Dp| zW6{g4BdwZK!(Np=+PJm(UPWjYU-;@vRrC7PPG4Fe@#Rv=h5V?`%O9-zpQrxw-oL*O y_SJ_UTK&(K^TmJdH?s2cwtB6dEL?57a*t4L>kCG(YavA4I_~~@|KkiA3=9B~Q(U$H literal 0 HcmV?d00001 diff --git a/integration_test/testdata/foo.yaml b/integration_test/testdata/foo.yaml new file mode 100644 index 00000000..98711e64 --- /dev/null +++ b/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 diff --git a/integration_test/testdata/konfig.yaml b/integration_test/testdata/konfig.yaml new file mode 100644 index 00000000..a8a33f6f --- /dev/null +++ b/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