package kustomize import ( "embed" "fmt" "io/fs" "testing" "sigs.k8s.io/kustomize/api/krusty" ktypes "sigs.k8s.io/kustomize/api/types" ) //go:embed testdata/fs/* var testFS embed.FS func TestFS(t *testing.T) { // Root our FS so we dont have to deal with all the noise s, err := fs.Sub(testFS, "testdata/fs") if err != nil { t.Fatal(err) } kfs := &FS{FS: s} t.Run("Exists", func(t *testing.T) { tcs := []struct { path string expected bool }{ {"kustomization.yaml", true}, {"base/kustomization.yaml", true}, {"base/manifests.yaml", true}, {"kustomization.yml", false}, {"/kustomization.yaml", false}, // fs.PathError {"/base/kustomization.yaml", false}, // fs.PathError {"/very/wild/path/m8.yaml", false}, // fs.PathError } for i, tc := range tcs { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { exists := kfs.Exists(tc.path) switch { case exists && !tc.expected: t.Error("path shouldn't have existed", tc.path) case !exists && tc.expected: t.Error("path should have existed", tc.path) } }) } }) t.Run("IsDir", func(t *testing.T) { tcs := []struct { path string expected bool }{ {"base", true}, {".", true}, {"kustomization.yaml", false}, {"base/kustomization.yaml", false}, {"base/manifests.yaml", false}, {"/very/wild/path/m8.yaml", false}, // fs.PathError } for i, tc := range tcs { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) { isdir := kfs.IsDir(tc.path) switch { case isdir && !tc.expected: t.Error("unexpected dir", tc.path) case !isdir && tc.expected: t.Error("expected dir", tc.path) } }) } }) t.Run("Kustomize Build", func(t *testing.T) { k := krusty.MakeKustomizer( &krusty.Options{ LoadRestrictions: ktypes.LoadRestrictionsNone, PluginConfig: ktypes.DisabledPluginConfig(), Reorder: krusty.ReorderOptionLegacy, }, ) _, err := k.Run(kfs, ".") if err != nil { t.Error(err) } }) }