Skip to content

Commit 7b2bf9c

Browse files
edcdavidopenshift-merge-bot[bot]
authored andcommitted
Add unit tests
Signed-off-by: David Elie-Dit-Cosaque <[email protected]>
1 parent d69cf61 commit 7b2bf9c

File tree

7 files changed

+1190
-0
lines changed

7 files changed

+1190
-0
lines changed

internal/patches_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ package internal
33

44
import (
55
"fmt"
6+
"os"
7+
"path/filepath"
68
"strings"
79
"testing"
810

911
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
12+
"sigs.k8s.io/kustomize/kyaml/filesys"
1013

1114
"open-cluster-management.io/policy-generator-plugin/internal/types"
1215
)
@@ -298,3 +301,45 @@ func TestApplyPatchesInvalidPatch(t *testing.T) {
298301
"ToasterOven.v1.[noGrp]/configmap2.default"
299302
assertEqual(t, err.Error(), expected)
300303
}
304+
305+
func TestInitializeInMemoryKustomizeDir(t *testing.T) {
306+
tmpDir := t.TempDir()
307+
testSchemaPath := filepath.Join(tmpDir, "myschema.json")
308+
309+
// Create test in memory file system
310+
afSys := filesys.MakeFsInMemory()
311+
f, err := os.Create(testSchemaPath)
312+
assertEqual(t, err, nil)
313+
314+
defer f.Close()
315+
316+
type args struct {
317+
fSys filesys.FileSystem
318+
schema string
319+
}
320+
321+
tests := []struct {
322+
name string
323+
args args
324+
wantErr bool
325+
}{
326+
{
327+
name: "ok",
328+
args: args{fSys: afSys, schema: testSchemaPath},
329+
wantErr: false,
330+
},
331+
{
332+
name: "schema file not present",
333+
args: args{fSys: afSys, schema: "myotherschema.json"},
334+
wantErr: true,
335+
},
336+
}
337+
338+
for _, tt := range tests {
339+
t.Run(tt.name, func(t *testing.T) {
340+
if err := InitializeInMemoryKustomizeDir(tt.args.fSys, tt.args.schema); (err != nil) != tt.wantErr {
341+
t.Errorf("InitializeInMemoryKustomizeDir() error = %v, wantErr %v", err, tt.wantErr)
342+
}
343+
})
344+
}
345+
}

0 commit comments

Comments
 (0)