Skip to content

Commit

Permalink
Check for existence of default dir in test
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskim06 committed Jun 5, 2020
1 parent cab58f1 commit 7665a1b
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions integration_test/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,11 @@ func TestKrewIndexAutoMigration(t *testing.T) {
defer cleanup()

test.WithEnv(constants.EnableMultiIndexSwitch, 1).WithDefaultIndex()
prepareOldIndex(test)
prepareOldIndexLayout(test)

// any command here should cause the index migration to occur
out, err := test.Krew("index", "list").Run()
if err != nil {
t.Errorf("command failed: %v", err)
}
if !strings.Contains(string(out), "krew-index.git") {
test.Krew("index", "list").RunOrFail()
if !isIndexMigrated(test) {
t.Error("output should include the default index after migration")
}
}
Expand All @@ -49,13 +46,10 @@ func TestKrewMigrationSkippedWithNoCommand(t *testing.T) {
defer cleanup()

test.WithEnv(constants.EnableMultiIndexSwitch, 1).WithDefaultIndex()
prepareOldIndex(test)
prepareOldIndexLayout(test)

out, err := test.Krew().Run()
if err != nil {
t.Errorf("command failed: %v", err)
}
if strings.Contains(string(out), "Migration completed") {
test.Krew().RunOrFail()
if isIndexMigrated(test) {
t.Error("output should not include the migration message")
}
}
Expand All @@ -81,7 +75,19 @@ func TestKrewUnsupportedVersion(t *testing.T) {
}
}

func prepareOldIndex(it *ITest) {
func isIndexMigrated(it *ITest) bool {
indexPath := it.TempDir().Path("index/default")
if _, err := os.Stat(indexPath); err == nil {
return true
} else if os.IsNotExist(err) {
return false
} else {
it.t.Fatal(err)
return false
}
}

func prepareOldIndexLayout(it *ITest) {
indexPath := it.TempDir().Path("index/default")
tmpPath := it.TempDir().Path("tmp_index")
newPath := it.TempDir().Path("index")
Expand Down

0 comments on commit 7665a1b

Please sign in to comment.