Skip to content
Permalink
Browse files

Improve logic to determine if receipts migration is necessary (#377)

* 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 46eaf89db446ff0f7f288fe0f6960681106aa313
@@ -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)
}
@@ -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
@@ -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/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{"store/konfig/konfig.sh"},
filesPresent: []string{"bin/foo"},
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)
}

0 comments on commit 46eaf89

Please sign in to comment.
You can’t perform that action at this time.