Skip to content

Commit

Permalink
Merge pull request #22 from Pungyeon/imports_fix
Browse files Browse the repository at this point in the history
fixing broken imports
  • Loading branch information
Pungyeon authored Jan 12, 2021
2 parents 94049ad + 654ce1c commit 33fc49c
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 19 deletions.
2 changes: 1 addition & 1 deletion article/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ Running these tests, gives us the following output:
```
--- FAIL: TestStringValidation (0.00s)
--- FAIL: TestStringValidation/nil_string (0.00s)
/Users/lassemartinjakobsen/projects/json-validation/required/string_test.go:34: <nil>
/Users/lassemartinjakobsen/projects/required/required/string_test.go:34: <nil>
```

Wait, What? So it turns out, that life is just not that simple in the land of Go. The reason for this, is that when we pass the `"{}"` JSON string, the `json.Unmarshal` will ignore the fields which aren't present. This means that because the `name` property doesn't appear in the JSON, the `UnmarshalJSON` function is never called, as it is completely skipped. Therefore, we never actually get a chance to check whether our required field contains anything, and therefore our tests fail miserably.
Expand Down
7 changes: 1 addition & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
module github.com/Pungyeon/required

go 1.12
go 1.15

require (
github.com/davecgh/go-spew v1.1.1
github.com/guregu/null v3.4.0+incompatible
honnef.co/go/tools v0.0.1-2020.1.5 // indirect
)
8 changes: 3 additions & 5 deletions pkg/json/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import (
"errors"
"reflect"

"github.com/Pungyeon/json-validation/pkg/token"

"github.com/Pungyeon/json-validation/pkg/structtag"

"github.com/Pungyeon/json-validation/pkg/required"
"github.com/Pungyeon/required/pkg/required"
"github.com/Pungyeon/required/pkg/structtag"
"github.com/Pungyeon/required/pkg/token"
)

func Parse(tokens token.Tokens, v interface{}) error {
Expand Down
8 changes: 3 additions & 5 deletions pkg/json/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import (
"regexp"
"testing"

"github.com/Pungyeon/json-validation/pkg/lexer"

"github.com/Pungyeon/json-validation/pkg/token"

"github.com/Pungyeon/json-validation/pkg/structtag"
"github.com/Pungyeon/required/pkg/lexer"
"github.com/Pungyeon/required/pkg/structtag"
"github.com/Pungyeon/required/pkg/token"
)

type TestObject struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/json/unmarshal.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package json

import "github.com/Pungyeon/json-validation/pkg/lexer"
import "github.com/Pungyeon/required/pkg/lexer"

func Unmarshal(data []byte, v interface{}) error {
tokens, err := lexer.Lex(string(data))
Expand Down
2 changes: 1 addition & 1 deletion pkg/lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package lexer
import (
"errors"

"github.com/Pungyeon/json-validation/pkg/token"
"github.com/Pungyeon/required/pkg/token"
)

var (
Expand Down

0 comments on commit 33fc49c

Please sign in to comment.