Skip to content

Commit 9f83688

Browse files
authored
use an exact number for search integration test (#864)
1 parent 48b3ea1 commit 9f83688

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

integration_test/search_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"sort"
2020
"strings"
2121
"testing"
22+
23+
"sigs.k8s.io/krew/pkg/constants"
2224
)
2325

2426
func TestKrewSearchAll(t *testing.T) {
@@ -27,9 +29,10 @@ func TestKrewSearchAll(t *testing.T) {
2729
test := NewTest(t)
2830

2931
output := test.WithDefaultIndex().Krew("search").RunOrFailOutput()
30-
if plugins := lines(output); len(plugins) < 10 {
32+
availablePlugins := test.IndexPluginCount(constants.DefaultIndexName)
33+
if plugins := lines(output); len(plugins)-1 != availablePlugins {
3134
// the first line is the header
32-
t.Errorf("Expected at least %d plugins", len(plugins)-1)
35+
t.Errorf("Expected %d plugins, got %d", availablePlugins, len(plugins)-1)
3336
}
3437
}
3538

integration_test/testutil_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,21 @@ func (it *ITest) WithCustomIndexFromDefault(name string) *ITest {
194194
return it
195195
}
196196

197+
// IndexPluginCount returns the number of plugins available in a given index.
198+
func (it *ITest) IndexPluginCount(name string) int {
199+
indexPath := environment.NewPaths(it.Root()).IndexPluginsPath(name)
200+
indexDir, err := os.Open(indexPath)
201+
if err != nil {
202+
it.t.Fatal(err)
203+
}
204+
defer indexDir.Close()
205+
plugins, err := indexDir.Readdirnames(-1)
206+
if err != nil {
207+
it.t.Fatal(err)
208+
}
209+
return len(plugins)
210+
}
211+
197212
// WithEnv sets an environment variable for the krew run.
198213
func (it *ITest) WithEnv(key string, value interface{}) *ITest {
199214
if key == "KREW_ROOT" {

0 commit comments

Comments
 (0)