Skip to content

Commit

Permalink
Use special "detached" index for manifest plugins (#568)
Browse files Browse the repository at this point in the history
* Use special detached index for manifest plugins

* Check receipt index when installing from manifest in integration tests

* Code review changes
  • Loading branch information
chriskim06 authored Mar 30, 2020
1 parent 87a2695 commit e7104f2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
5 changes: 2 additions & 3 deletions cmd/krew/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"sigs.k8s.io/krew/internal/index/indexscanner"
"sigs.k8s.io/krew/internal/installation"
"sigs.k8s.io/krew/internal/pathutil"
"sigs.k8s.io/krew/pkg/constants"
"sigs.k8s.io/krew/pkg/index"
)

Expand Down Expand Up @@ -119,7 +118,7 @@ Remarks:
}
install = append(install, pluginEntry{
p: plugin,
indexName: constants.DefaultIndexName,
indexName: "detached",
})
} else if *manifestURL != "" {
plugin, err := readPluginFromURL(*manifestURL)
Expand All @@ -128,7 +127,7 @@ Remarks:
}
install = append(install, pluginEntry{
p: plugin,
indexName: constants.DefaultIndexName,
indexName: "detached",
})
}

Expand Down
3 changes: 3 additions & 0 deletions integration_test/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func TestKrewInstall_Manifest(t *testing.T) {
"--manifest", filepath.Join("testdata", validPlugin+constants.ManifestExtension)).
RunOrFail()
test.AssertExecutableInPATH("kubectl-" + validPlugin)
test.AssertPluginFromIndex(t, "detached", validPlugin)
}

func TestKrewInstall_ManifestURL(t *testing.T) {
Expand All @@ -146,6 +147,7 @@ func TestKrewInstall_ManifestURL(t *testing.T) {
"--manifest-url", srv+"/"+validPlugin+constants.ManifestExtension).
RunOrFail()
test.AssertExecutableInPATH("kubectl-" + validPlugin)
test.AssertPluginFromIndex(t, "detached", validPlugin)
}

func TestKrewInstall_ManifestAndArchive(t *testing.T) {
Expand All @@ -159,6 +161,7 @@ func TestKrewInstall_ManifestAndArchive(t *testing.T) {
"--archive", filepath.Join("testdata", fooPlugin+".tar.gz")).
RunOrFail()
test.AssertExecutableInPATH("kubectl-" + fooPlugin)
test.AssertPluginFromIndex(t, "detached", fooPlugin)
}

func TestKrewInstall_OnlyArchive(t *testing.T) {
Expand Down
14 changes: 14 additions & 0 deletions integration_test/testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

"sigs.k8s.io/krew/internal/environment"
"sigs.k8s.io/krew/internal/indexmigration"
"sigs.k8s.io/krew/internal/installation/receipt"
"sigs.k8s.io/krew/internal/testutil"
"sigs.k8s.io/krew/pkg/constants"
)
Expand Down Expand Up @@ -155,6 +156,19 @@ func (it *ITest) AssertExecutableNotInPATH(file string) {
}
}

// AssertPluginFromIndex asserts that a receipt exists for the given plugin and
// that it is from the specified index.
func (it *ITest) AssertPluginFromIndex(t *testing.T, indexName, plugin string) {
receiptPath := environment.NewPaths(it.Root()).PluginInstallReceiptPath(plugin)
r, err := receipt.Load(receiptPath)
if err != nil {
t.Fatalf("error loading receipt: %v", err)
}
if r.Status.Source.Name != indexName {
t.Errorf("wanted index '%s', got: '%s'", indexName, r.Status.Source.Name)
}
}

// Krew configures the runner to call krew with arguments args.
func (it *ITest) Krew(args ...string) *ITest {
it.plugin = "krew"
Expand Down

0 comments on commit e7104f2

Please sign in to comment.