Skip to content

Commit

Permalink
test: add unknown field test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Fernando Cainelli <[email protected]>
  • Loading branch information
cainelli committed Jul 17, 2024
1 parent 7dd4708 commit dcd3654
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/pkg/parser/testcase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import (
"github.com/stretchr/testify/require"
)

func TestUnknownField(t *testing.T) {
_, err := ParseTestCases([]string{"testdata/invalid_test.yml"}, true)
require.ErrorContains(t, err, "json: unknown field")
}

func TestParseTestCases(t *testing.T) {
expectedTestCases := []*TestCase{
{Description: "happy path users"},
Expand All @@ -27,7 +32,6 @@ func TestParseTestCases(t *testing.T) {
if !testPass {
t.Errorf("could not find expected description:'%v'", expected.Description)
}

}
}

Expand Down
16 changes: 16 additions & 0 deletions internal/pkg/parser/testdata/invalid_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
testCases:
- description: a test
unknownField: true # not a valid field
wantMatch: true
request:
authority:
- www.example.com
method:
- GET
uri:
- /users
route:
- destination:
host: users.users.svc.cluster.local
port:
number: 80
18 changes: 18 additions & 0 deletions internal/pkg/parser/testdata/invalid_vs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: networking.istio.io/v1
kind: VirtualService
metadata:
name: example
namespace: example
spec:
unknownField: true # not a valid field
hosts:
- www.example.com
http:
- match:
- uri:
regex: /users(/.*)?
route:
- destination:
host: users.users.svc.cluster.local
port:
number: 80
5 changes: 5 additions & 0 deletions internal/pkg/parser/virtualservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ func TestParseMultipleVirtualServices(t *testing.T) {
}
}
}

func TestVirtualServiceUnknownFields(t *testing.T) {
_, err := ParseVirtualServices([]string{}, true)
require.ErrorContains(t, err, "json: unknown field")
}

0 comments on commit dcd3654

Please sign in to comment.