Skip to content

Commit

Permalink
chore: makefile add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: RealAnna <[email protected]>
  • Loading branch information
RealAnna committed Feb 6, 2024
1 parent 066763d commit 01a63d9
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions lifecycle-operator/converter/convert_app_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"github.com/stretchr/testify/require"

Check failure on line 4 in lifecycle-operator/converter/convert_app_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint (lifecycle-operator, lifecycle-operator/)

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"os"
"testing"

Check failure on line 7 in lifecycle-operator/converter/convert_app_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint (lifecycle-operator, lifecycle-operator/)

File is not `gci`-ed with --skip-generated -s standard -s default (gci)

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const inputFileName = "example_keptnapp.yaml"
Expand Down Expand Up @@ -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)
}

0 comments on commit 01a63d9

Please sign in to comment.