Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jsonschema] Bug: error not returned from Encoder #63

Closed
smyrman opened this issue Dec 15, 2016 · 2 comments
Closed

[jsonschema] Bug: error not returned from Encoder #63

smyrman opened this issue Dec 15, 2016 · 2 comments

Comments

@smyrman
Copy link
Collaborator

smyrman commented Dec 15, 2016

While donig some test-cleanup in the jsonschema package, I found a bug where errors in encoding a validator are never returned from jsonschema.Encoder.

I found this bug while changing this test:

-func TestErrNotImplemented(t *testing.T) {
-       validator := &schema.IP{}
-       b := new(bytes.Buffer)
-       assert.Equal(t, ErrNotImplemented, validatorToJSONSchema(b, validator))
-}

Into one that tests the public interface:

+type dummyValidator struct{}
+
+func (v dummyValidator) Validate(value interface{}) (interface{}, error) {
+       return value, nil
+}
+
+func TestErrNotImplemented(t *testing.T) {
+       s := schema.Schema{
+               Fields: schema.Fields{
+                       "i": {
+                               Validator: &dummyValidator{},
+                       },
+               },
+       }
+       enc := jsonschema.NewEncoder(new(bytes.Buffer))
+       assert.Equal(t, jsonschema.ErrNotImplemented, enc.Encode(&s))
+}

PS! The result is the same if &schema.IP{} is used as Validator in the new test.

I am trying to see if I can fix this together with my change.

smyrman added a commit to smyrman/rest-layer that referenced this issue Dec 15, 2016
- Replaces encoder_test.go (encoding package) with example_test.go (jsonschema package).
- Replaces remaining tests in jsonschema_test.go with (table-)tests
  testing the pulbic interface. The new tests are placed in
  <typeName>_test.go or all_test.go.
- Solves Issue rs#63 (found by test change) where errors from
  validatorToJSONSchema and serializeField where never propagated.
@smyrman
Copy link
Collaborator Author

smyrman commented Dec 15, 2016

@yanfali, pinging you about this so you are aware. Should be fixed by #64.

smyrman added a commit to smyrman/rest-layer that referenced this issue Dec 15, 2016
Testing:
- Replaces encoder_test.go (encoding package) with example_test.go
  (jsonschema package).
- Replaces remaining tests in jsonschema_test.go with tests that test
  the pulbic interface. The new tests are placed in {typeName}_test.go
  or all_test.go.
- Remove go 1.6 testing support (no longer run by CI).

Code:
- Solves Issue rs#63 (found by test change) where errors from
  validatorToJSONSchema and serializeField where never propagated.
- Encodes schema.Fields in alphabetical order to allow example test.
- Order type methods to appear right below type definition.
smyrman added a commit to smyrman/rest-layer that referenced this issue Dec 16, 2016
Testing:
- Replaces encoder_test.go (encoding package) with example_test.go
  (jsonschema package).
- Replaces remaining tests in jsonschema_test.go with tests that test
  the pulbic interface. The new tests are placed in {typeName}_test.go
  or all_test.go.
- Remove go 1.6 testing support (no longer run by CI).

Code:
- Solves Issue rs#63 (found by test change) where errors from
  validatorToJSONSchema and serializeField where never propagated.
- Encodes schema.Fields in alphabetical order to allow example test.
- Order type methods to appear right below type definition.
rs pushed a commit that referenced this issue Dec 16, 2016
Testing:
- Replaces encoder_test.go (encoding package) with example_test.go
  (jsonschema package).
- Replaces remaining tests in jsonschema_test.go with tests that test
  the pulbic interface. The new tests are placed in {typeName}_test.go
  or all_test.go.
- Remove go 1.6 testing support (no longer run by CI).

Code:
- Solves Issue #63 (found by test change) where errors from
  validatorToJSONSchema and serializeField where never propagated.
- Encodes schema.Fields in alphabetical order to allow example test.
- Order type methods to appear right below type definition.
@smyrman
Copy link
Collaborator Author

smyrman commented Dec 16, 2016

Since #64 is merged, this issue can be closed.

@smyrman smyrman closed this as completed Dec 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant