mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-16 13:22:09 +08:00
chore: modify the code style to specify binding type
This commit is contained in:
parent
26952eb3b0
commit
891b33f888
@ -2016,13 +2016,26 @@ func TestContextShouldBindBodyWithJSON(t *testing.T) {
|
|||||||
Foo string `json:"foo" binding:"required"`
|
Foo string `json:"foo" binding:"required"`
|
||||||
}
|
}
|
||||||
objJSON := typeJSON{}
|
objJSON := typeJSON{}
|
||||||
if tt.bindingBody != binding.JSON {
|
|
||||||
assert.Error(t, c.ShouldBindBodyWithJSON(&objJSON))
|
if tt.bindingBody == binding.JSON{
|
||||||
assert.Equal(t, typeJSON{}, objJSON)
|
|
||||||
} else {
|
|
||||||
assert.NoError(t, c.ShouldBindBodyWithJSON(&objJSON))
|
assert.NoError(t, c.ShouldBindBodyWithJSON(&objJSON))
|
||||||
assert.Equal(t, typeJSON{"FOO"}, objJSON)
|
assert.Equal(t, typeJSON{"FOO"}, objJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tt.bindingBody == binding.XML {
|
||||||
|
assert.Error(t, c.ShouldBindBodyWithJSON(&objJSON))
|
||||||
|
assert.Equal(t, typeJSON{}, objJSON)
|
||||||
|
}
|
||||||
|
|
||||||
|
if tt.bindingBody == binding.YAML {
|
||||||
|
assert.Error(t, c.ShouldBindBodyWithJSON(&objJSON))
|
||||||
|
assert.Equal(t, typeJSON{}, objJSON)
|
||||||
|
}
|
||||||
|
|
||||||
|
if tt.bindingBody == binding.TOML {
|
||||||
|
assert.Error(t, c.ShouldBindBodyWithJSON(&objJSON))
|
||||||
|
assert.Equal(t, typeJSON{}, objJSON)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2067,13 +2080,26 @@ func TestContextShouldBindBodyWithXML(t *testing.T) {
|
|||||||
Foo string `xml:"foo" binding:"required"`
|
Foo string `xml:"foo" binding:"required"`
|
||||||
}
|
}
|
||||||
objXML := typeXML{}
|
objXML := typeXML{}
|
||||||
if tt.bindingBody != binding.XML {
|
|
||||||
|
if tt.bindingBody == binding.JSON {
|
||||||
assert.Error(t, c.ShouldBindBodyWithXML(&objXML))
|
assert.Error(t, c.ShouldBindBodyWithXML(&objXML))
|
||||||
assert.Equal(t, typeXML{}, objXML)
|
assert.Equal(t, typeXML{}, objXML)
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if tt.bindingBody == binding.XML {
|
||||||
assert.NoError(t, c.ShouldBindBodyWithXML(&objXML))
|
assert.NoError(t, c.ShouldBindBodyWithXML(&objXML))
|
||||||
assert.Equal(t, typeXML{"FOO"}, objXML)
|
assert.Equal(t, typeXML{"FOO"}, objXML)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tt.bindingBody == binding.YAML{
|
||||||
|
assert.Error(t, c.ShouldBindBodyWithXML(&objXML))
|
||||||
|
assert.Equal(t, typeXML{}, objXML)
|
||||||
|
}
|
||||||
|
|
||||||
|
if tt.bindingBody == binding.TOML {
|
||||||
|
assert.Error(t, c.ShouldBindBodyWithXML(&objXML))
|
||||||
|
assert.Equal(t, typeXML{}, objXML)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2118,13 +2144,27 @@ func TestContextShouldBindBodyWithYAML(t *testing.T) {
|
|||||||
Foo string `yaml:"foo" binding:"required"`
|
Foo string `yaml:"foo" binding:"required"`
|
||||||
}
|
}
|
||||||
objYAML := typeYAML{}
|
objYAML := typeYAML{}
|
||||||
if tt.bindingBody != binding.YAML && tt.bindingBody != binding.JSON {
|
|
||||||
assert.Error(t, c.ShouldBindBodyWithYAML(&objYAML))
|
// YAML belongs to a super collection of JSON, so JSON can be parsed by YAML
|
||||||
assert.Equal(t, typeYAML{}, objYAML)
|
if tt.bindingBody == binding.JSON {
|
||||||
} else {
|
|
||||||
assert.NoError(t, c.ShouldBindBodyWithYAML(&objYAML))
|
assert.NoError(t, c.ShouldBindBodyWithYAML(&objYAML))
|
||||||
assert.Equal(t, typeYAML{"FOO"}, objYAML)
|
assert.Equal(t, typeYAML{"FOO"}, objYAML)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tt.bindingBody == binding.XML {
|
||||||
|
assert.Error(t, c.ShouldBindBodyWithYAML(&objYAML))
|
||||||
|
assert.Equal(t, typeYAML{}, objYAML)
|
||||||
|
}
|
||||||
|
|
||||||
|
if tt.bindingBody == binding.YAML {
|
||||||
|
assert.NoError(t, c.ShouldBindBodyWithYAML(&objYAML))
|
||||||
|
assert.Equal(t, typeYAML{"FOO"}, objYAML)
|
||||||
|
}
|
||||||
|
|
||||||
|
if tt.bindingBody == binding.TOML {
|
||||||
|
assert.Error(t, c.ShouldBindBodyWithYAML(&objYAML))
|
||||||
|
assert.Equal(t, typeYAML{}, objYAML)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2169,10 +2209,23 @@ func TestContextShouldBindBodyWithTOML(t *testing.T) {
|
|||||||
Foo string `toml:"foo" binding:"required"`
|
Foo string `toml:"foo" binding:"required"`
|
||||||
}
|
}
|
||||||
objTOML := typeTOML{}
|
objTOML := typeTOML{}
|
||||||
if tt.bindingBody != binding.TOML {
|
|
||||||
|
if tt.bindingBody == binding.JSON {
|
||||||
assert.Error(t, c.ShouldBindBodyWithTOML(&objTOML))
|
assert.Error(t, c.ShouldBindBodyWithTOML(&objTOML))
|
||||||
assert.Equal(t, typeTOML{}, objTOML)
|
assert.Equal(t, typeTOML{}, objTOML)
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if tt.bindingBody == binding.XML {
|
||||||
|
assert.Error(t, c.ShouldBindBodyWithTOML(&objTOML))
|
||||||
|
assert.Equal(t, typeTOML{}, objTOML)
|
||||||
|
}
|
||||||
|
|
||||||
|
if tt.bindingBody == binding.YAML {
|
||||||
|
assert.Error(t, c.ShouldBindBodyWithTOML(&objTOML))
|
||||||
|
assert.Equal(t, typeTOML{}, objTOML)
|
||||||
|
}
|
||||||
|
|
||||||
|
if tt.bindingBody == binding.TOML {
|
||||||
assert.NoError(t, c.ShouldBindBodyWithTOML(&objTOML))
|
assert.NoError(t, c.ShouldBindBodyWithTOML(&objTOML))
|
||||||
assert.Equal(t, typeTOML{"FOO"}, objTOML)
|
assert.Equal(t, typeTOML{"FOO"}, objTOML)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user