-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add option to ignore snowflake unqote error & tests
- Loading branch information
Showing
2 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package snowflake | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"strconv" | ||
"testing" | ||
) | ||
|
||
func TestID_UnmarshalJSON(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
data []byte | ||
expected ID | ||
allowUnquoted bool | ||
err error | ||
}{ | ||
{ | ||
name: "null", | ||
data: []byte("null"), | ||
expected: 0, | ||
allowUnquoted: false, | ||
err: nil, | ||
}, | ||
{ | ||
name: "valid id", | ||
data: []byte(`"123456"`), | ||
expected: 123456, | ||
allowUnquoted: false, | ||
err: nil, | ||
}, | ||
{ | ||
name: "invalid id", | ||
data: []byte(`"id"`), | ||
expected: 0, | ||
allowUnquoted: false, | ||
err: strconv.ErrSyntax, | ||
}, | ||
{ | ||
name: "unquoted 0", | ||
data: []byte("0"), | ||
expected: 0, | ||
allowUnquoted: false, | ||
err: nil, | ||
}, | ||
{ | ||
name: "quoted 0", | ||
data: []byte(`"0"`), | ||
expected: 0, | ||
allowUnquoted: false, | ||
err: nil, | ||
}, | ||
{ | ||
name: "unquoted 1", | ||
data: []byte("1"), | ||
expected: 0, | ||
allowUnquoted: true, | ||
err: strconv.ErrSyntax, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
var id ID | ||
err := json.Unmarshal(tt.data, &id) | ||
|
||
if !errors.Is(err, tt.err) { | ||
t.Errorf("expected error %v, got %v", tt.err, err) | ||
} | ||
if id != tt.expected { | ||
t.Errorf("expected %d, got %d", tt.expected, id) | ||
} | ||
}) | ||
} | ||
} |