mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
[Tests] add tests for disallow_unknown_fields
This commit is contained in:
@@ -2,3 +2,4 @@
|
||||
*_easyjson.go
|
||||
*.iml
|
||||
.idea
|
||||
*.swp
|
||||
|
||||
@@ -37,6 +37,7 @@ generate: root build
|
||||
.root/bin/easyjson .root/src/$(PKG)/tests/named_type.go
|
||||
.root/bin/easyjson .root/src/$(PKG)/tests/custom_map_key_type.go
|
||||
.root/bin/easyjson .root/src/$(PKG)/tests/embedded_type.go
|
||||
.root/bin/easyjson -disallow_unknown_fields .root/src/$(PKG)/tests/disallow_unknown.go
|
||||
|
||||
test: generate root
|
||||
go test \
|
||||
|
||||
@@ -53,6 +53,8 @@ Usage of easyjson:
|
||||
use lowerCamelCase instead of CamelCase by default
|
||||
-stubs
|
||||
only generate stubs for marshaler/unmarshaler funcs
|
||||
-disallow_unknown_fields
|
||||
return error if some unknown field in json occured
|
||||
```
|
||||
|
||||
Using `-all` will generate marshalers/unmarshalers for all Go structs in the
|
||||
|
||||
@@ -232,3 +232,11 @@ func TestUnmarshalStructWithEmbeddedPtrStruct(t *testing.T) {
|
||||
t.Errorf("easyjson.Unmarshal() = %#v; want %#v", s, structWithInterfaceValueFilled)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDisallowUnknown(t *testing.T) {
|
||||
var d DisallowUnknown
|
||||
err := easyjson.Unmarshal([]byte(disallowUnknownString), &d)
|
||||
if err == nil {
|
||||
t.Error("want error, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package tests
|
||||
|
||||
//easyjson:json
|
||||
type DisallowUnknown struct {
|
||||
FieldOne string `json:"field_one"`
|
||||
}
|
||||
|
||||
var disallowUnknownString = `{"field_one": "one", "field_two": "two"}`
|
||||
Reference in New Issue
Block a user