Repository: zeromicro/go-zero
Pull request #2778 (2023-01-11 06:50:54)

chore: add tests

codecov-commenter: # [Codecov](https://codecov.io/gh/zeromicro/go-zero/pull/2778?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#2778](https://codecov.io/gh/zeromicro/go-zero/pull/2778?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (fa1294f) into [master](https://codecov.io/gh/zeromicro/go-zero/commit/0b176e17aca8a379256cb2a8d626b7d574659c4c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (0b176e1) will **increase** coverage by `0.00%`.
> The diff coverage is `100.00%`.


| [Impacted Files](https://codecov.io/gh/zeromicro/go-zero/pull/2778?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [core/mapping/unmarshaler.go](https://codecov.io/gh/zeromicro/go-zero/pull/2778?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-Y29yZS9tYXBwaW5nL3VubWFyc2hhbGVyLmdv) | `88.71% <100.00%> (+0.55%)` | :arrow_up: |
| [core/logx/rotatelogger.go](https://codecov.io/gh/zeromicro/go-zero/pull/2778?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-Y29yZS9sb2d4L3JvdGF0ZWxvZ2dlci5nbw==) | `71.58% <0.00%> (-1.11%)` | :arrow_down: |


Patch:
diff --git a/core/mapping/unmarshaler.go b/core/mapping/unmarshaler.go
index b7285057..1ec535d1 100644
--- a/core/mapping/unmarshaler.go
+++ b/core/mapping/unmarshaler.go
@@ -752,7 +752,7 @@ func (u *Unmarshaler) processNamedFieldWithValueFromString(fieldType reflect.Typ
 		switch mt := mapValue.(type) {
 		case string:
 			checkValue = mt
-		case json.Number:
+		case fmt.Stringer:
 			checkValue = mt.String()
 		default:
 			return fmt.Errorf("the value in map is not string or json.Number, but %s",


Test patch:
diff --git a/core/mapping/unmarshaler_test.go b/core/mapping/unmarshaler_test.go
index 83229fd4..99a0984d 100644
--- a/core/mapping/unmarshaler_test.go
+++ b/core/mapping/unmarshaler_test.go
@@ -260,7 +260,7 @@ func TestUnmarshalIntWithString(t *testing.T) {
 		}
 
 		var in inner
-		assert.Nil(t, UnmarshalKey(m, &in))
+		assert.NoError(t, UnmarshalKey(m, &in))
 		assert.Equal(t, int64(0), in.Int)
 	})
 
@@ -273,9 +273,37 @@ func TestUnmarshalIntWithString(t *testing.T) {
 		}
 
 		var in inner
-		assert.Nil(t, UnmarshalKey(m, &in))
+		assert.NoError(t, UnmarshalKey(m, &in))
 		assert.Equal(t, int64(0), in.Int)
 	})
+
+	t.Run("int with options", func(t *testing.T) {
+		type inner struct {
+			Int int64 `key:"int,string,options=[0,1]"`
+		}
+		m := map[string]interface{}{
+			"int": nil,
+		}
+
+		var in inner
+		assert.Error(t, UnmarshalKey(m, &in))
+	})
+
+	t.Run("int with options", func(t *testing.T) {
+		type (
+			StrType string
+
+			inner struct {
+				Int int64 `key:"int,string,options=[0,1]"`
+			}
+		)
+		m := map[string]interface{}{
+			"int": StrType("0"),
+		}
+
+		var in inner
+		assert.Error(t, UnmarshalKey(m, &in))
+	})
 }
 
 func TestUnmarshalBoolSliceRequired(t *testing.T) {