From 2cd27d8568202457ca10504d6d7ea1a7d0b3bc74 Mon Sep 17 00:00:00 2001 From: Evgeny Abramovich Date: Sat, 29 Jun 2024 15:52:33 -0300 Subject: [PATCH] Added test cases --- tests/schema/invalid/not-full-mapping.yaml | 3 +++ tests/schema/invalid_test.go | 11 ++++++++++- tests/schema/valid/minimal-valid.yaml | 1 - tests/schema/valid/short-mapping.yaml | 3 +++ tests/schema/valid_test.go | 7 ++++++- 5 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 tests/schema/invalid/not-full-mapping.yaml create mode 100644 tests/schema/valid/short-mapping.yaml diff --git a/tests/schema/invalid/not-full-mapping.yaml b/tests/schema/invalid/not-full-mapping.yaml new file mode 100644 index 00000000..7d42a511 --- /dev/null +++ b/tests/schema/invalid/not-full-mapping.yaml @@ -0,0 +1,3 @@ +mappings: + - from: http://localhost + to: diff --git a/tests/schema/invalid_test.go b/tests/schema/invalid_test.go index f2fa4ff4..b8620c60 100644 --- a/tests/schema/invalid_test.go +++ b/tests/schema/invalid_test.go @@ -1,10 +1,11 @@ package schema_test import ( - "github.com/evg4b/uncors/tests/schema" "path/filepath" "testing" + "github.com/evg4b/uncors/tests/schema" + "github.com/evg4b/uncors/testing/testutils" "github.com/samber/lo" "github.com/stretchr/testify/assert" @@ -30,6 +31,14 @@ func TestInvalidJsonSchema(t *testing.T) { "mappings: Array must have at least 1 items", }, }, + { + name: "not full mapping", + file: testdir("not-full-mapping.yaml"), + errors: []string{ + "mappings.0: Must validate one and only one schema (oneOf)", + "mappings.0.to: Invalid type. Expected: string, given: null", + }, + }, } for _, testCase := range cases { diff --git a/tests/schema/valid/minimal-valid.yaml b/tests/schema/valid/minimal-valid.yaml index 88524b40..7396b730 100644 --- a/tests/schema/valid/minimal-valid.yaml +++ b/tests/schema/valid/minimal-valid.yaml @@ -1,4 +1,3 @@ -http-port: 3000 mappings: - from: http://localhost to: https://github.com \ No newline at end of file diff --git a/tests/schema/valid/short-mapping.yaml b/tests/schema/valid/short-mapping.yaml new file mode 100644 index 00000000..ef695731 --- /dev/null +++ b/tests/schema/valid/short-mapping.yaml @@ -0,0 +1,3 @@ +http-port: 3000 +mappings: + - http://localhost: https://github.com \ No newline at end of file diff --git a/tests/schema/valid_test.go b/tests/schema/valid_test.go index ac4a7988..03f5ffd8 100644 --- a/tests/schema/valid_test.go +++ b/tests/schema/valid_test.go @@ -1,10 +1,11 @@ package schema_test import ( - "github.com/evg4b/uncors/tests/schema" "path/filepath" "testing" + "github.com/evg4b/uncors/tests/schema" + "github.com/evg4b/uncors/testing/testutils" "github.com/stretchr/testify/assert" @@ -27,6 +28,10 @@ func TestValidJsonSchema(t *testing.T) { name: "minimal valid file", file: testdir("minimal-valid.yaml"), }, + { + name: "short mapping", + file: testdir("short-mapping.yaml"), + }, } for _, testCase := range cases {