From 7a3d03cd28c0e808be2ee77735323feb0e4b8e8f Mon Sep 17 00:00:00 2001 From: Cornelius Weig Date: Tue, 12 Nov 2019 00:02:15 +0100 Subject: [PATCH 1/3] Improve logic to determine if repo migration is necessary --- pkg/receiptsmigration/migration.go | 11 ++--------- pkg/receiptsmigration/migration_test.go | 6 +++--- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/pkg/receiptsmigration/migration.go b/pkg/receiptsmigration/migration.go index d6df854b..b29fbdac 100644 --- a/pkg/receiptsmigration/migration.go +++ b/pkg/receiptsmigration/migration.go @@ -44,19 +44,12 @@ func Done(newPaths environment.Paths) (bool, error) { if err != nil { return false, err } - store, err := ioutil.ReadDir(newPaths.InstallPath()) + plugins, err := ioutil.ReadDir(newPaths.BinPath()) if err != nil { return false, err } - var hasInstalledPlugins bool - for _, entry := range store { - if entry.IsDir() { - hasInstalledPlugins = true - break - } - } - + hasInstalledPlugins := len(plugins) > 0 hasNoReceipts := len(receipts) == 0 return !(hasInstalledPlugins && hasNoReceipts), nil diff --git a/pkg/receiptsmigration/migration_test.go b/pkg/receiptsmigration/migration_test.go index 4742b9ea..820d1c96 100644 --- a/pkg/receiptsmigration/migration_test.go +++ b/pkg/receiptsmigration/migration_test.go @@ -39,7 +39,7 @@ func TestIsMigrated(t *testing.T) { }{ { name: "One plugin and receipts", - filesPresent: []string{"store/konfig/konfig.sh", "receipts/present"}, + filesPresent: []string{"bin/konfig/konfig.sh", "receipts/present"}, expected: true, }, { @@ -48,7 +48,7 @@ func TestIsMigrated(t *testing.T) { }, { name: "When a plugin is installed but no receipts", - filesPresent: []string{"store/konfig/konfig.sh"}, + filesPresent: []string{"bin/konfig/konfig.sh"}, expected: false, }, { @@ -69,7 +69,7 @@ func TestIsMigrated(t *testing.T) { newPaths := environment.MustGetKrewPaths() _ = os.MkdirAll(tmpDir.Path("receipts"), os.ModePerm) - _ = os.MkdirAll(tmpDir.Path("store"), os.ModePerm) + _ = os.MkdirAll(tmpDir.Path("bin"), os.ModePerm) for _, name := range test.filesPresent { touch(tmpDir, name) } From 4efa7f049653353e72824faf7c05801ca8827c78 Mon Sep 17 00:00:00 2001 From: Cornelius Weig Date: Tue, 12 Nov 2019 01:01:43 +0100 Subject: [PATCH 2/3] Improve test setup --- pkg/receiptsmigration/migration_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/receiptsmigration/migration_test.go b/pkg/receiptsmigration/migration_test.go index 820d1c96..f8e3fc96 100644 --- a/pkg/receiptsmigration/migration_test.go +++ b/pkg/receiptsmigration/migration_test.go @@ -39,7 +39,7 @@ func TestIsMigrated(t *testing.T) { }{ { name: "One plugin and receipts", - filesPresent: []string{"bin/konfig/konfig.sh", "receipts/present"}, + filesPresent: []string{"bin/foo", "receipts/present"}, expected: true, }, { @@ -48,7 +48,7 @@ func TestIsMigrated(t *testing.T) { }, { name: "When a plugin is installed but no receipts", - filesPresent: []string{"bin/konfig/konfig.sh"}, + filesPresent: []string{"bin/foo"}, expected: false, }, { From b169f8441a4f2730a82490c51dc8f24eae24b800 Mon Sep 17 00:00:00 2001 From: Cornelius Weig Date: Wed, 13 Nov 2019 00:35:03 +0100 Subject: [PATCH 3/3] Ensure that integration tests pass the receipts migration check --- integration_test/testutil_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/integration_test/testutil_test.go b/integration_test/testutil_test.go index da2ba7ab..c4e5fa35 100644 --- a/integration_test/testutil_test.go +++ b/integration_test/testutil_test.go @@ -84,6 +84,10 @@ func setupKrewBin(t *testing.T, tempDir *testutil.TempDir) string { if err := os.MkdirAll(binPath, 0755); err != nil { t.Fatal(err) } + + // todo(corneliusweig): when the receipts migration logic is removed, this becomes obsolete + tempDir.Write("receipts/krew.notyaml", []byte("must be present for receipts migration check")) + if err := os.Symlink(krewBinary, filepath.Join(binPath, "kubectl-krew")); err != nil { t.Fatalf("cannot link krew binary: %s", err) }