1 package kustomize
2
3 import (
4 "embed"
5 "fmt"
6 "io/fs"
7 "testing"
8
9 "sigs.k8s.io/kustomize/api/krusty"
10 ktypes "sigs.k8s.io/kustomize/api/types"
11 )
12
13
14 var testFS embed.FS
15
16 func TestFS(t *testing.T) {
17
18 s, err := fs.Sub(testFS, "testdata/fs")
19 if err != nil {
20 t.Fatal(err)
21 }
22 kfs := &FS{FS: s}
23
24 t.Run("Exists", func(t *testing.T) {
25 tcs := []struct {
26 path string
27 expected bool
28 }{
29 {"kustomization.yaml", true},
30 {"base/kustomization.yaml", true},
31 {"base/manifests.yaml", true},
32 {"kustomization.yml", false},
33 {"/kustomization.yaml", false},
34 {"/base/kustomization.yaml", false},
35 {"/very/wild/path/m8.yaml", false},
36 }
37
38 for i, tc := range tcs {
39 t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
40 exists := kfs.Exists(tc.path)
41 switch {
42 case exists && !tc.expected:
43 t.Error("path shouldn't have existed", tc.path)
44 case !exists && tc.expected:
45 t.Error("path should have existed", tc.path)
46 }
47 })
48 }
49 })
50
51 t.Run("IsDir", func(t *testing.T) {
52 tcs := []struct {
53 path string
54 expected bool
55 }{
56 {"base", true},
57 {".", true},
58 {"kustomization.yaml", false},
59 {"base/kustomization.yaml", false},
60 {"base/manifests.yaml", false},
61 {"/very/wild/path/m8.yaml", false},
62 }
63
64 for i, tc := range tcs {
65 t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
66 isdir := kfs.IsDir(tc.path)
67 switch {
68 case isdir && !tc.expected:
69 t.Error("unexpected dir", tc.path)
70 case !isdir && tc.expected:
71 t.Error("expected dir", tc.path)
72 }
73 })
74 }
75 })
76
77 t.Run("Kustomize Build", func(t *testing.T) {
78 k := krusty.MakeKustomizer(
79 &krusty.Options{
80 LoadRestrictions: ktypes.LoadRestrictionsNone,
81 PluginConfig: ktypes.DisabledPluginConfig(),
82 Reorder: krusty.ReorderOptionLegacy,
83 },
84 )
85
86 _, err := k.Run(kfs, ".")
87 if err != nil {
88 t.Error(err)
89 }
90 })
91 }
92
View as plain text