Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logic to determine if receipts migration is necessary #377

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 {
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
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",
filesPresent: []string{"store/konfig/konfig.sh", "receipts/present"},
filesPresent: []string{"bin/konfig/konfig.sh", "receipts/present"},
Copy link
Member

@ahmetb ahmetb Nov 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not very realistic since it created dirs under bin/
let's just add bin/konfig.sh directly.

also if "konfig" the word isn't relevant, let's say "foo", (ditto below)

but it seems like this has simplified the tests a good deal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, makes much more sense!

expected: true,
},
{
Expand All @@ -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,
},
{
Expand All @@ -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)
}
Expand Down