Skip to content

Commit

Permalink
Add failure tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ptodev committed Oct 31, 2024
1 parent dc0a3cd commit 0ef415c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions syntax/vm/vm_stdlib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,41 @@ func TestVM_Stdlib(t *testing.T) {
}
}

func TestVM_Stdlib_Errors(t *testing.T) {
tt := []struct {
name string
input string
expectedErr string
}{
// Map tests
{
// Error: invalid RHS type - string.
"targets.merge",
`targets.merge([{"a" = "a1", "b" = "b1"}], "a", ["a"])`,
`"a" should be array, got string`,
},
{
// Error: invalid RHS type - an array with strings.
"targets.merge",
`targets.merge([{"a" = "a1", "b" = "b1"}], ["a"], ["a"])`,
`"a" should be object, got string`,
},
}

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
expr, err := parser.ParseExpression(tc.input)
require.NoError(t, err)

eval := vm.New(expr)

rv := reflect.New(reflect.TypeOf([]map[string]interface{}{}))
err = eval.Evaluate(nil, rv.Interface())
require.ErrorContains(t, err, tc.expectedErr)
})
}
}

func TestStdlibCoalesce(t *testing.T) {
t.Setenv("TEST_VAR2", "Hello!")

Expand Down

0 comments on commit 0ef415c

Please sign in to comment.