github.com/wolfi-dev/wolfictl@v0.16.11/pkg/configs/build/selection_test.go (about) 1 package build 2 3 import ( 4 "context" 5 "testing" 6 7 "chainguard.dev/melange/pkg/config" 8 "github.com/stretchr/testify/assert" 9 "github.com/stretchr/testify/require" 10 "github.com/wolfi-dev/wolfictl/pkg/configs" 11 rwos "github.com/wolfi-dev/wolfictl/pkg/configs/rwfs/os" 12 ) 13 14 func TestSelection(t *testing.T) { 15 fsys := rwos.DirFS("testdata/index-1") 16 17 index, err := configs.NewIndex[config.Configuration](context.Background(), fsys, newConfigurationDecodeFunc(fsys)) 18 require.NoError(t, err) 19 20 s := index.Select() 21 22 t.Run("Select", func(t *testing.T) { 23 assert.Equal(t, 2, s.Len()) 24 }) 25 26 t.Run("WhereName", func(t *testing.T) { 27 cheeseSelection := s.WhereName("cheese") 28 require.Equal(t, 1, cheeseSelection.Len()) 29 assert.Equal(t, "cheese", cheeseSelection.Entries()[0].Configuration().Package.Name) 30 31 nonexistentSelection := s.WhereName("not-a-real-name!") 32 assert.Equal(t, 0, nonexistentSelection.Len()) 33 }) 34 35 t.Run("WhereFilePath", func(t *testing.T) { 36 cheeseSelection := s.WhereFilePath("config-2.yaml") 37 require.Equal(t, 1, cheeseSelection.Len()) 38 assert.Equal(t, "cheese", cheeseSelection.Entries()[0].Configuration().Package.Name) 39 40 nonexistentSelection := s.WhereFilePath("not-a-real-path!") 41 assert.Equal(t, 0, nonexistentSelection.Len()) 42 }) 43 }