Skip to content

Commit

Permalink
Improve logic to determine if receipts migration is necessary (#377)
Browse files Browse the repository at this point in the history
* Improve logic to determine if repo migration is necessary

* Improve test setup

* Ensure that integration tests pass the receipts migration check
  • Loading branch information
corneliusweig authored and k8s-ci-robot committed Nov 15, 2019
1 parent e8deb96 commit 46eaf89
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
4 changes: 4 additions & 0 deletions integration_test/testutil_test.go
Expand Up @@ -84,6 +84,10 @@ func setupKrewBin(t *testing.T, tempDir *testutil.TempDir) string {
if err := os.MkdirAll(binPath, 0755); err != nil { if err := os.MkdirAll(binPath, 0755); err != nil {
t.Fatal(err) 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 { if err := os.Symlink(krewBinary, filepath.Join(binPath, "kubectl-krew")); err != nil {
t.Fatalf("cannot link krew binary: %s", err) t.Fatalf("cannot link krew binary: %s", err)
} }
Expand Down
11 changes: 2 additions & 9 deletions pkg/receiptsmigration/migration.go
Expand Up @@ -44,19 +44,12 @@ func Done(newPaths environment.Paths) (bool, error) {
if err != nil { if err != nil {
return false, err return false, err
} }
store, err := ioutil.ReadDir(newPaths.InstallPath()) plugins, err := ioutil.ReadDir(newPaths.BinPath())
if err != nil { if err != nil {
return false, err return false, err
} }


var hasInstalledPlugins bool hasInstalledPlugins := len(plugins) > 0
for _, entry := range store {
if entry.IsDir() {
hasInstalledPlugins = true
break
}
}

hasNoReceipts := len(receipts) == 0 hasNoReceipts := len(receipts) == 0


return !(hasInstalledPlugins && hasNoReceipts), nil return !(hasInstalledPlugins && hasNoReceipts), nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/receiptsmigration/migration_test.go
Expand Up @@ -39,7 +39,7 @@ func TestIsMigrated(t *testing.T) {
}{ }{
{ {
name: "One plugin and receipts", name: "One plugin and receipts",
filesPresent: []string{"store/konfig/konfig.sh", "receipts/present"}, filesPresent: []string{"bin/foo", "receipts/present"},
expected: true, expected: true,
}, },
{ {
Expand All @@ -48,7 +48,7 @@ func TestIsMigrated(t *testing.T) {
}, },
{ {
name: "When a plugin is installed but no receipts", name: "When a plugin is installed but no receipts",
filesPresent: []string{"store/konfig/konfig.sh"}, filesPresent: []string{"bin/foo"},
expected: false, expected: false,
}, },
{ {
Expand All @@ -69,7 +69,7 @@ func TestIsMigrated(t *testing.T) {
newPaths := environment.MustGetKrewPaths() newPaths := environment.MustGetKrewPaths()


_ = os.MkdirAll(tmpDir.Path("receipts"), os.ModePerm) _ = 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 { for _, name := range test.filesPresent {
touch(tmpDir, name) touch(tmpDir, name)
} }
Expand Down

0 comments on commit 46eaf89

Please sign in to comment.