Skip to content

Commit

Permalink
use an exact number for search integration test (#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskim06 authored Oct 13, 2024
1 parent 48b3ea1 commit 9f83688
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions integration_test/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"sort"
"strings"
"testing"

"sigs.k8s.io/krew/pkg/constants"
)

func TestKrewSearchAll(t *testing.T) {
Expand All @@ -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)
}
}

Expand Down
15 changes: 15 additions & 0 deletions integration_test/testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit 9f83688

Please sign in to comment.