diff --git a/integration_test/search_test.go b/integration_test/search_test.go index 6f0d748d..43af51a5 100644 --- a/integration_test/search_test.go +++ b/integration_test/search_test.go @@ -19,6 +19,8 @@ import ( "sort" "strings" "testing" + + "sigs.k8s.io/krew/pkg/constants" ) func TestKrewSearchAll(t *testing.T) { @@ -27,9 +29,10 @@ func TestKrewSearchAll(t *testing.T) { test := NewTest(t) output := test.WithDefaultIndex().Krew("search").RunOrFailOutput() - if plugins := lines(output); len(plugins) < 10 { + availablePlugins := test.IndexPluginCount(constants.DefaultIndexName) + if plugins := lines(output); len(plugins)-1 != availablePlugins { // the first line is the header - t.Errorf("Expected at least %d plugins", len(plugins)-1) + t.Errorf("Expected %d plugins, got %d", availablePlugins, len(plugins)-1) } } diff --git a/integration_test/testutil_test.go b/integration_test/testutil_test.go index 66ebc984..e4f9afcc 100644 --- a/integration_test/testutil_test.go +++ b/integration_test/testutil_test.go @@ -194,6 +194,21 @@ func (it *ITest) WithCustomIndexFromDefault(name string) *ITest { return it } +// IndexPluginCount returns the number of plugins available in a given index. +func (it *ITest) IndexPluginCount(name string) int { + indexPath := environment.NewPaths(it.Root()).IndexPluginsPath(name) + indexDir, err := os.Open(indexPath) + if err != nil { + it.t.Fatal(err) + } + defer indexDir.Close() + plugins, err := indexDir.Readdirnames(-1) + if err != nil { + it.t.Fatal(err) + } + return len(plugins) +} + // WithEnv sets an environment variable for the krew run. func (it *ITest) WithEnv(key string, value interface{}) *ITest { if key == "KREW_ROOT" {