Skip to content

Commit de2459b

Browse files
authored
Use environment.Paths instead of calculating paths (#627)
1 parent f90ce36 commit de2459b

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

integration_test/index_test.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"strings"
2121
"testing"
2222

23+
"sigs.k8s.io/krew/internal/environment"
2324
"sigs.k8s.io/krew/pkg/constants"
2425
)
2526

@@ -39,10 +40,11 @@ func TestKrewIndexAdd(t *testing.T) {
3940
if err := test.Krew("index", "add", "../../usr/bin", constants.DefaultIndexURI); err == nil {
4041
t.Fatal("expected index add with path characters to fail")
4142
}
42-
if _, err := test.Krew("index", "add", "foo", test.TempDir().Path("index/"+constants.DefaultIndexName)).Run(); err != nil {
43+
index := environment.NewPaths(test.Root()).IndexPath(constants.DefaultIndexName)
44+
if _, err := test.Krew("index", "add", "foo", index).Run(); err != nil {
4345
t.Fatalf("error adding new index: %v", err)
4446
}
45-
if _, err := test.Krew("index", "add", "foo", test.TempDir().Path("index/"+constants.DefaultIndexName)).Run(); err == nil {
47+
if _, err := test.Krew("index", "add", "foo", index).Run(); err == nil {
4648
t.Fatal("expected adding same index to fail")
4749
}
4850
}
@@ -73,7 +75,8 @@ func TestKrewIndexAddShowsSecurityWarning(t *testing.T) {
7375
defer cleanup()
7476

7577
test.WithDefaultIndex()
76-
out := string(test.Krew("index", "add", "foo", test.TempDir().Path("index/"+constants.DefaultIndexName)).RunOrFailOutput())
78+
index := environment.NewPaths(test.Root()).IndexPath(constants.DefaultIndexName)
79+
out := string(test.Krew("index", "add", "foo", index).RunOrFailOutput())
7780
if !strings.Contains(out, "WARNING: You have added a new index") {
7881
t.Errorf("expected output to contain warning when adding custom index: %v", out)
7982
}
@@ -107,7 +110,7 @@ func TestKrewIndexList_NoIndexes(t *testing.T) {
107110
defer cleanup()
108111

109112
test.WithDefaultIndex()
110-
index := test.TempDir().Path("index")
113+
index := environment.NewPaths(test.Root()).IndexBase()
111114
if err := os.RemoveAll(index); err != nil {
112115
t.Fatalf("error removing default index: %v", err)
113116
}

integration_test/migration_test.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import (
1919
"os"
2020
"strings"
2121
"testing"
22+
23+
"sigs.k8s.io/krew/internal/environment"
24+
"sigs.k8s.io/krew/pkg/constants"
2225
)
2326

2427
func TestKrewIndexAutoMigration(t *testing.T) {
@@ -59,16 +62,17 @@ func TestKrewUnsupportedVersion(t *testing.T) {
5962
}
6063

6164
func isIndexMigrated(it *ITest) bool {
62-
indexPath := it.TempDir().Path("index/default")
65+
indexPath := environment.NewPaths(it.Root()).IndexPath(constants.DefaultIndexName)
6366
_, err := os.Stat(indexPath)
6467
return err == nil
6568
}
6669

6770
// TODO remove when testing indexmigration is no longer necessary
6871
func prepareOldIndexLayout(it *ITest) {
69-
indexPath := it.TempDir().Path("index/default")
72+
paths := environment.NewPaths(it.Root())
73+
indexPath := paths.IndexPath(constants.DefaultIndexName)
7074
tmpPath := it.TempDir().Path("tmp_index")
71-
newPath := it.TempDir().Path("index")
75+
newPath := paths.IndexBase()
7276
if err := os.Rename(indexPath, tmpPath); err != nil {
7377
it.t.Fatal(err)
7478
}

integration_test/testutil_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ func (it *ITest) WithDefaultIndex() *ITest {
192192
// to be called before this function. This is a helper function for working with custom indexes in the
193193
// integration tests so that developers don't need to alias the cloned default index each time.
194194
func (it *ITest) WithCustomIndexFromDefault(name string) *ITest {
195-
it.Krew("index", "add", name, it.TempDir().Path("index/"+constants.DefaultIndexName)).RunOrFail()
195+
indexPath := environment.NewPaths(it.Root()).IndexPath(constants.DefaultIndexName)
196+
it.Krew("index", "add", name, indexPath).RunOrFail()
196197
return it
197198
}
198199

integration_test/upgrade_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ func TestKrewUpgrade_ValidPluginInstalledFromManifest(t *testing.T) {
189189
Krew("install", validPlugin).
190190
RunOrFail()
191191

192-
validPluginPath := filepath.Join(test.Root(), "index", "default", "plugins", validPlugin+constants.ManifestExtension)
192+
pluginPath := environment.NewPaths(test.Root()).IndexPluginsPath(constants.DefaultIndexName)
193+
validPluginPath := filepath.Join(pluginPath, validPlugin+constants.ManifestExtension)
193194
if err := os.Remove(validPluginPath); err != nil {
194195
t.Fatalf("can't remove valid plugin from index: %q", validPluginPath)
195196
}

0 commit comments

Comments
 (0)