Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Jan 16, 2024
1 parent 793ca8b commit edf70bb
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions kong2kic/kong2kic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import (

var baseLocation = "testdata/"

func fixJSONstream(input string) string {
// this is a stream of json files, must update to an actual json array
return "[" + strings.Replace(input, "}{", "},{", -1) + "]"
}

func compareFileContent(t *testing.T, expectedFilename string, actualContent []byte) {
expected, err := os.ReadFile(baseLocation + expectedFilename)
if err != nil {
Expand All @@ -22,7 +27,8 @@ func compareFileContent(t *testing.T, expectedFilename string, actualContent []b
os.WriteFile(actualFilename, actualContent, 0o600)

if strings.HasSuffix(expectedFilename, ".json") {
require.JSONEq(t, string(expected), string(actualContent))
// this is a stream of json files, must update to an actual json array
require.JSONEq(t, fixJSONstream(string(expected)), fixJSONstream(string(actualContent)))
} else {
require.YAMLEq(t, string(expected), string(actualContent))
}
Expand Down Expand Up @@ -86,7 +92,13 @@ func Test_convertKongGatewayToIngress(t *testing.T) {
assert.Fail(t, err.Error())
}

output, err := MarshalKongToKICYaml(inputContent, tt.builderType)
var output []byte
if strings.HasSuffix(tt.outputFilename, ".json") {
output, err = MarshalKongToKICJson(inputContent, tt.builderType)
} else {
output, err = MarshalKongToKICYaml(inputContent, tt.builderType)
}

if err == nil {
compareFileContent(t, tt.outputFilename, output)
} else if (err != nil) != tt.wantErr {
Expand Down

0 comments on commit edf70bb

Please sign in to comment.