fix marshal ptr in httpc (#1789)

* fix marshal ptr in httpc

* add more tests

* add more tests

* add more tests

* fix issue on options and optional both provided
This commit is contained in:
Kevin Wan
2022-04-15 19:07:34 +08:00
committed by GitHub
parent ee88abce14
commit cb4fcf2c6c
4 changed files with 122 additions and 0 deletions

View File

@@ -987,6 +987,43 @@ func TestUnmarshalWithStringOptionsCorrect(t *testing.T) {
ast.Equal("2", in.Correct)
}
func TestUnmarshalOptionsOptional(t *testing.T) {
type inner struct {
Value string `key:"value,options=first|second,optional"`
OptionalValue string `key:"optional_value,options=first|second,optional"`
Foo string `key:"foo,options=[bar,baz]"`
Correct string `key:"correct,options=1|2"`
}
m := map[string]interface{}{
"value": "first",
"foo": "bar",
"correct": "2",
}
var in inner
ast := assert.New(t)
ast.Nil(UnmarshalKey(m, &in))
ast.Equal("first", in.Value)
ast.Equal("", in.OptionalValue)
ast.Equal("bar", in.Foo)
ast.Equal("2", in.Correct)
}
func TestUnmarshalOptionsOptionalWrongValue(t *testing.T) {
type inner struct {
Value string `key:"value,options=first|second,optional"`
OptionalValue string `key:"optional_value,options=first|second,optional"`
WrongValue string `key:"wrong_value,options=first|second,optional"`
}
m := map[string]interface{}{
"value": "first",
"wrong_value": "third",
}
var in inner
assert.NotNil(t, UnmarshalKey(m, &in))
}
func TestUnmarshalStringOptionsWithStringOptionsNotString(t *testing.T) {
type inner struct {
Value string `key:"value,options=first|second"`