Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use an exact number for search integration test #864

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading