From 01a63d9c8589d266549a43322138b36529f1fa9a Mon Sep 17 00:00:00 2001 From: RealAnna Date: Tue, 6 Feb 2024 10:53:18 +0100 Subject: [PATCH] chore: makefile add unit test Signed-off-by: RealAnna --- .../converter/convert_app_test.go | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/lifecycle-operator/converter/convert_app_test.go b/lifecycle-operator/converter/convert_app_test.go index 24fe5ec0cf..2e9edf33cf 100644 --- a/lifecycle-operator/converter/convert_app_test.go +++ b/lifecycle-operator/converter/convert_app_test.go @@ -1,10 +1,10 @@ package main import ( + "github.com/stretchr/testify/require" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "os" "testing" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) const inputFileName = "example_keptnapp.yaml" @@ -75,3 +75,34 @@ func TestAddKeptnAnnotation(t *testing.T) { } }) } + +func TestParseAndTransformBadYAML(t *testing.T) { + invalidYAML := []byte("This is not valid YAML") + // Attempt to parse and transform the invalid app YAML + _, _, err := parseAndTransform(invalidYAML) + if err == nil { + t.Error("Expected an error but got nil") + } +} + +func TestTransformKeptnApp_UnmarshalFailure(t *testing.T) { + tmpDir := t.TempDir() + + // Create a temporary file with invalid YAML content + invalidYAML := []byte("This is not valid YAML") + err := os.WriteFile(tmpDir+"/validfile.yaml", invalidYAML, 0644) + require.NoError(t, err) + + // Attempt to transform the invalid YAML file + err = transformKeptnApp(tmpDir+"/validfile.yaml", tmpDir+"/output.yaml") + + require.Error(t, err) +} + +func TestTransformKeptnApp_ReadFileFailure(t *testing.T) { + //unexisting file + tmpDir := t.TempDir() + err := transformKeptnApp(tmpDir+"/validfile.yaml", tmpDir+"/output.yaml") + require.Error(t, err) + t.Log(err) +}