From a52d4905c9448438d9a59c19d04620b4fa7e722b Mon Sep 17 00:00:00 2001 From: Jay179-sudo Date: Tue, 9 Jul 2024 18:37:44 +0530 Subject: [PATCH] Added unit tests for payload file Signed-off-by: Jay179-sudo --- pkg/payload/load_test.go | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 pkg/payload/load_test.go diff --git a/pkg/payload/load_test.go b/pkg/payload/load_test.go new file mode 100644 index 00000000..bd6d74ee --- /dev/null +++ b/pkg/payload/load_test.go @@ -0,0 +1,44 @@ +package payload + +import ( + "path/filepath" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestLoad(t *testing.T) { + basePath := "../../test/commands/scan" + tests := []struct { + name string + path string + wantErr bool + }{ + { + name: "Valid JSON File", + path: filepath.Join(basePath, "/tf-ec2/payload.json"), + wantErr: false, + }, + { + name: "Valid YAML File", + path: filepath.Join(basePath, "/pod-no-latest/payload.yaml"), + wantErr: false, + }, + { + name: "Not a YAML or a JSON File", + path: filepath.Join(basePath, "/dockerfile/out.txt"), + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + _, err := Load(tt.path) + if tt.wantErr { + require.Error(t, err) + } else { + require.NoError(t, err) + } + }) + } +}