From 828074f40a5367c86324dfb11558f2f2cf78ffc9 Mon Sep 17 00:00:00 2001 From: Cornelius Weig Date: Thu, 4 Jul 2019 23:14:17 +0200 Subject: [PATCH 1/6] Add test cases for `krew install` with --archive and --manifest options --- integration_test/install_test.go | 54 +++++++++++++++++++++- integration_test/testdata/konfig.yaml | 28 +++++++++++ integration_test/testdata/test-foo.tar.gz | Bin 0 -> 146 bytes integration_test/testdata/test-foo.yaml | 28 +++++++++++ 4 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 integration_test/testdata/konfig.yaml create mode 100644 integration_test/testdata/test-foo.tar.gz create mode 100644 integration_test/testdata/test-foo.yaml diff --git a/integration_test/install_test.go b/integration_test/install_test.go index a3b3580e..f8cb8e68 100644 --- a/integration_test/install_test.go +++ b/integration_test/install_test.go @@ -14,7 +14,17 @@ package integrationtest -import "testing" +import ( + "path/filepath" + "strings" + "testing" + + "sigs.k8s.io/krew/pkg/constants" +) + +const ( + fooPlugin = "test-foo" +) func TestKrewInstall(t *testing.T) { skipShort(t) @@ -25,3 +35,45 @@ 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-" + strings.ReplaceAll(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/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 diff --git a/integration_test/testdata/test-foo.tar.gz b/integration_test/testdata/test-foo.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..dbf4917cc0ab7aaa333f3e0f60bfcb230f4c3de1 GIT binary patch literal 146 zcmb2|=3oE;Cg!)7jGK-Ih%`KmP8W5w?$|u{#QKH7e+h~l-(Py!l1#x004O$LGu6r literal 0 HcmV?d00001 diff --git a/integration_test/testdata/test-foo.yaml b/integration_test/testdata/test-foo.yaml new file mode 100644 index 00000000..1c8f82db --- /dev/null +++ b/integration_test/testdata/test-foo.yaml @@ -0,0 +1,28 @@ +apiVersion: krew.googlecontainertools.github.com/v1alpha2 +kind: Plugin +metadata: + name: test-foo +spec: + version: "v0.1.0" + shortDescription: a plugin in central index with small size + platforms: + - uri: https://foo.bar/test-foo.tar.gz + sha256: e1b260213a6989ce1f1d3f03bc1312346e70e565828465ae989f11f32fd4956a + bin: test-foo + files: + - from: ./test-foo + to: "." + selector: + matchExpressions: + - key: os + operator: In + values: ["darwin", "linux"] + - uri: https://foo.bar/test-foo.tar.gz + sha256: e1b260213a6989ce1f1d3f03bc1312346e70e565828465ae989f11f32fd4956a + bin: test-foo.exe + files: + - from: ./test-foo + to: test-foo.exe + selector: + matchLabels: + os: windows From c5e10ffa1976f01ef5933b5be2ca54f8cefb1a9a Mon Sep 17 00:00:00 2001 From: Cornelius Weig Date: Thu, 4 Jul 2019 23:21:09 +0200 Subject: [PATCH 2/6] Improve formatting --- integration_test/install_test.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/integration_test/install_test.go b/integration_test/install_test.go index f8cb8e68..612beaf0 100644 --- a/integration_test/install_test.go +++ b/integration_test/install_test.go @@ -42,9 +42,8 @@ func TestKrewInstall_Manifest(t *testing.T) { test, cleanup := NewTest(t) defer cleanup() - test. - Krew("install", - "--manifest", filepath.Join("testdata", validPlugin+constants.ManifestExtension)). + test.Krew("install", + "--manifest", filepath.Join("testdata", validPlugin+constants.ManifestExtension)). RunOrFail() test.AssertExecutableInPATH("kubectl-" + validPlugin) } @@ -55,10 +54,9 @@ func TestKrewInstall_ManifestAndArchive(t *testing.T) { test, cleanup := NewTest(t) defer cleanup() - test. - Krew("install", - "--manifest", filepath.Join("testdata", fooPlugin+constants.ManifestExtension), - "--archive", filepath.Join("testdata", fooPlugin+".tar.gz")). + test.Krew("install", + "--manifest", filepath.Join("testdata", fooPlugin+constants.ManifestExtension), + "--archive", filepath.Join("testdata", fooPlugin+".tar.gz")). RunOrFail() test.AssertExecutableInPATH("kubectl-" + strings.ReplaceAll(fooPlugin, "-", "_")) } @@ -69,9 +67,8 @@ func TestKrewInstall_OnlyArchiveFails(t *testing.T) { test, cleanup := NewTest(t) defer cleanup() - err := test. - Krew("install", - "--archive", filepath.Join("testdata", fooPlugin+".tar.gz")). + err := test.Krew("install", + "--archive", filepath.Join("testdata", fooPlugin+".tar.gz")). Run() if err == nil { t.Errorf("Expected install to fail but was successful") From 830cf26974737d490a505a20e0c294962a4c4d50 Mon Sep 17 00:00:00 2001 From: Cornelius Weig Date: Fri, 5 Jul 2019 01:01:41 +0200 Subject: [PATCH 3/6] ReplaceAll was added in go 1.12, but krew uses 1.11 --- integration_test/install_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_test/install_test.go b/integration_test/install_test.go index 612beaf0..40a4811a 100644 --- a/integration_test/install_test.go +++ b/integration_test/install_test.go @@ -58,7 +58,7 @@ func TestKrewInstall_ManifestAndArchive(t *testing.T) { "--manifest", filepath.Join("testdata", fooPlugin+constants.ManifestExtension), "--archive", filepath.Join("testdata", fooPlugin+".tar.gz")). RunOrFail() - test.AssertExecutableInPATH("kubectl-" + strings.ReplaceAll(fooPlugin, "-", "_")) + test.AssertExecutableInPATH("kubectl-" + strings.Replace(fooPlugin, "-", "_", -1)) } func TestKrewInstall_OnlyArchiveFails(t *testing.T) { From 64a2eef58116fd56afdc40426706d3fc2ba098d1 Mon Sep 17 00:00:00 2001 From: Cornelius Weig Date: Mon, 8 Jul 2019 21:32:30 +0200 Subject: [PATCH 4/6] Rename test plugin from `test-foo` to `foo` --- integration_test/install_test.go | 5 ++-- integration_test/testdata/foo.tar.gz | Bin 0 -> 146 bytes integration_test/testdata/foo.yaml | 28 ++++++++++++++++++++++ integration_test/testdata/test-foo.tar.gz | Bin 146 -> 0 bytes integration_test/testdata/test-foo.yaml | 28 ---------------------- 5 files changed, 30 insertions(+), 31 deletions(-) create mode 100644 integration_test/testdata/foo.tar.gz create mode 100644 integration_test/testdata/foo.yaml delete mode 100644 integration_test/testdata/test-foo.tar.gz delete mode 100644 integration_test/testdata/test-foo.yaml diff --git a/integration_test/install_test.go b/integration_test/install_test.go index 40a4811a..668f602c 100644 --- a/integration_test/install_test.go +++ b/integration_test/install_test.go @@ -16,14 +16,13 @@ package integrationtest import ( "path/filepath" - "strings" "testing" "sigs.k8s.io/krew/pkg/constants" ) const ( - fooPlugin = "test-foo" + fooPlugin = "foo" ) func TestKrewInstall(t *testing.T) { @@ -58,7 +57,7 @@ func TestKrewInstall_ManifestAndArchive(t *testing.T) { "--manifest", filepath.Join("testdata", fooPlugin+constants.ManifestExtension), "--archive", filepath.Join("testdata", fooPlugin+".tar.gz")). RunOrFail() - test.AssertExecutableInPATH("kubectl-" + strings.Replace(fooPlugin, "-", "_", -1)) + test.AssertExecutableInPATH("kubectl-" + fooPlugin) } func TestKrewInstall_OnlyArchiveFails(t *testing.T) { diff --git a/integration_test/testdata/foo.tar.gz b/integration_test/testdata/foo.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..6bec1f90e5a419114c4b79cf1b9cbb34b880ae96 GIT binary patch literal 146 zcmb2|=3oE;Cg!&%4>ulg5NUX5xxDLv+~T=6%D!hm-gfW*?88@bBs(Q&Y~a3Y3@Eh=^`g9ZZw02>HHrvLx| literal 0 HcmV?d00001 diff --git a/integration_test/testdata/foo.yaml b/integration_test/testdata/foo.yaml new file mode 100644 index 00000000..af0694d1 --- /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: e72bad12ce8faa84aae929894acad9d759a40d63befde2a9dcf6ba12487cc362 + bin: foo + files: + - from: ./foo + to: "." + selector: + matchExpressions: + - key: os + operator: In + values: ["darwin", "linux"] + - uri: https://foo.bar/foo.tar.gz + sha256: e72bad12ce8faa84aae929894acad9d759a40d63befde2a9dcf6ba12487cc362 + bin: foo.exe + files: + - from: ./foo + to: foo.exe + selector: + matchLabels: + os: windows diff --git a/integration_test/testdata/test-foo.tar.gz b/integration_test/testdata/test-foo.tar.gz deleted file mode 100644 index dbf4917cc0ab7aaa333f3e0f60bfcb230f4c3de1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 146 zcmb2|=3oE;Cg!)7jGK-Ih%`KmP8W5w?$|u{#QKH7e+h~l-(Py!l1#x004O$LGu6r diff --git a/integration_test/testdata/test-foo.yaml b/integration_test/testdata/test-foo.yaml deleted file mode 100644 index 1c8f82db..00000000 --- a/integration_test/testdata/test-foo.yaml +++ /dev/null @@ -1,28 +0,0 @@ -apiVersion: krew.googlecontainertools.github.com/v1alpha2 -kind: Plugin -metadata: - name: test-foo -spec: - version: "v0.1.0" - shortDescription: a plugin in central index with small size - platforms: - - uri: https://foo.bar/test-foo.tar.gz - sha256: e1b260213a6989ce1f1d3f03bc1312346e70e565828465ae989f11f32fd4956a - bin: test-foo - files: - - from: ./test-foo - to: "." - selector: - matchExpressions: - - key: os - operator: In - values: ["darwin", "linux"] - - uri: https://foo.bar/test-foo.tar.gz - sha256: e1b260213a6989ce1f1d3f03bc1312346e70e565828465ae989f11f32fd4956a - bin: test-foo.exe - files: - - from: ./test-foo - to: test-foo.exe - selector: - matchLabels: - os: windows From 72e1598239363a48f814e652e37176730349d176 Mon Sep 17 00:00:00 2001 From: Cornelius Weig Date: Mon, 8 Jul 2019 22:21:27 +0200 Subject: [PATCH 5/6] Use wildcard platform selector in test data --- integration_test/testdata/foo.yaml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/integration_test/testdata/foo.yaml b/integration_test/testdata/foo.yaml index af0694d1..532c1bc4 100644 --- a/integration_test/testdata/foo.yaml +++ b/integration_test/testdata/foo.yaml @@ -13,16 +13,4 @@ spec: - from: ./foo to: "." selector: - matchExpressions: - - key: os - operator: In - values: ["darwin", "linux"] - - uri: https://foo.bar/foo.tar.gz - sha256: e72bad12ce8faa84aae929894acad9d759a40d63befde2a9dcf6ba12487cc362 - bin: foo.exe - files: - - from: ./foo - to: foo.exe - selector: - matchLabels: - os: windows + matchLabels: {} From d757c9c3df44f742d22dc889f44022b76fcb2728 Mon Sep 17 00:00:00 2001 From: Cornelius Weig Date: Tue, 9 Jul 2019 13:02:10 +0200 Subject: [PATCH 6/6] Add windows version of the test plugin for testing on windows --- integration_test/testdata/foo.tar.gz | Bin 146 -> 199 bytes integration_test/testdata/foo.yaml | 20 ++++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/integration_test/testdata/foo.tar.gz b/integration_test/testdata/foo.tar.gz index 6bec1f90e5a419114c4b79cf1b9cbb34b880ae96..c0e61a1ba9cf13826b980e30f86971db77fc8475 100644 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 146 zcmb2|=3oE;Cg!&%4>ulg5NUX5xxDLv+~T=6%D!hm-gfW*?88@bBs(Q&Y~a3Y3@Eh=^`g9ZZw02>HHrvLx| diff --git a/integration_test/testdata/foo.yaml b/integration_test/testdata/foo.yaml index 532c1bc4..98711e64 100644 --- a/integration_test/testdata/foo.yaml +++ b/integration_test/testdata/foo.yaml @@ -7,10 +7,22 @@ spec: shortDescription: A valid plugin for integration tests platforms: - uri: https://foo.bar/foo.tar.gz - sha256: e72bad12ce8faa84aae929894acad9d759a40d63befde2a9dcf6ba12487cc362 - bin: foo + sha256: 354bad230cdd0966fc8c919476c4e6c7f2078b04a6ff7dead6a811cdc101d31e + bin: foo.sh files: - - from: ./foo + - from: ./foo.sh to: "." selector: - matchLabels: {} + 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