Test unmarshal nil for port

This commit is contained in:
9seconds
2021-04-01 21:14:51 +03:00
parent 132a01c27e
commit 6c92ec314d
2 changed files with 7 additions and 1 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ func (c *TypePort) UnmarshalJSON(data []byte) error {
return nil return nil
} }
intValue, err := strconv.ParseUint(string(data), 10, 16) intValue, err := strconv.ParseUint(string(data), 10, 64)
if err != nil { if err != nil {
return fmt.Errorf("port number is not a number: %w", err) return fmt.Errorf("port number is not a number: %w", err)
} }
+6
View File
@@ -18,6 +18,12 @@ type TypePortTestSuite struct {
suite.Suite suite.Suite
} }
func (suite *TypePortTestSuite) TestUnmarshalNil() {
typ := &config.TypePort{}
suite.NoError(typ.UnmarshalJSON(nil))
suite.Equal("0", typ.String())
}
func (suite *TypePortTestSuite) TestUnmarshalFail() { func (suite *TypePortTestSuite) TestUnmarshalFail() {
testData := []int{ testData := []int{
-1, -1,