Skip to content

Commit

Permalink
Add test covering single element -> slice coercion
Browse files Browse the repository at this point in the history
  • Loading branch information
lwc committed Apr 13, 2021
1 parent f57d1a0 commit 1d768a2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions codegen/testserver/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,24 @@ func TestInput(t *testing.T) {
require.NoError(t, err)
require.False(t, resp.InputNullableSlice)
})

t.Run("coerce single value to slice", func(t *testing.T) {
check := func(ctx context.Context, arg []string) (b bool, e error) {
return len(arg) == 1 && arg[0] == "coerced", nil
}
resolvers.QueryResolver.InputSlice = check
resolvers.QueryResolver.InputNullableSlice = check

var resp struct {
Coerced bool
}
var err error
err = c.Post(`query { coerced: inputSlice(arg: "coerced") }`, &resp)
require.NoError(t, err)
require.True(t, resp.Coerced)

err = c.Post(`query { coerced: inputNullableSlice(arg: "coerced") }`, &resp)
require.NoError(t, err)
require.True(t, resp.Coerced)
})
}

0 comments on commit 1d768a2

Please sign in to comment.