From 053e99a2d19bbcf8525d8b9515f73386a1c975df Mon Sep 17 00:00:00 2001 From: nico Date: Sun, 22 Sep 2024 06:37:06 +0800 Subject: [PATCH] add unit test --- common/structure/structure_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/common/structure/structure_test.go b/common/structure/structure_test.go index e5fe693d..266b828f 100644 --- a/common/structure/structure_test.go +++ b/common/structure/structure_test.go @@ -267,3 +267,21 @@ func TestStructure_TextUnmarshaller(t *testing.T) { err = decoder.Decode(rawMap, s) assert.NotNilf(t, err, "should throw error: %#v", s) } + +func TestStructure_Null(t *testing.T) { + rawMap := map[string]any{ + "opt": map[string]any{ + "bar": nil, + }, + } + + s := struct { + Opt struct { + Bar string `test:"bar,optional"` + } `test:"opt,optional"` + }{} + + err := decoder.Decode(rawMap, &s) + assert.Nil(t, err) + assert.Equal(t, s.Opt.Bar, "") +}