From d5d56e51d7e7a106b82fff208f8f385f5dd2bdf1 Mon Sep 17 00:00:00 2001 From: unknown <12gzk@163.com> Date: Thu, 12 May 2022 09:39:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E4=BE=8B=E8=A6=86?= =?UTF-8?q?=E7=9B=96=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- encoding/gproperties/gproperties.go | 6 ------ encoding/gproperties/gproperties_z_unit_test.go | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/encoding/gproperties/gproperties.go b/encoding/gproperties/gproperties.go index 53bf4e01e..c8fca7bc9 100644 --- a/encoding/gproperties/gproperties.go +++ b/encoding/gproperties/gproperties.go @@ -99,8 +99,6 @@ func deepSearch(m map[string]interface{}, path []string) map[string]interface{} } m3, ok := m2.(map[string]interface{}) if !ok { - // intermediate key is a value - // => replace with a new map m3 = make(map[string]interface{}) m[k] = m3 } @@ -113,12 +111,8 @@ func deepSearch(m map[string]interface{}, path []string) map[string]interface{} // flattenAndMergeMap recursively flattens the given map into a new map func flattenAndMergeMap(shadow map[string]interface{}, m map[string]interface{}, prefix string, delimiter string) map[string]interface{} { if shadow != nil && prefix != "" && shadow[prefix] != nil { - // prefix is shadowed => nothing more to flatten return shadow } - if shadow == nil { - shadow = make(map[string]interface{}) - } var m2 map[string]interface{} if prefix != "" { diff --git a/encoding/gproperties/gproperties_z_unit_test.go b/encoding/gproperties/gproperties_z_unit_test.go index 6f2ad9e42..39215dcd9 100644 --- a/encoding/gproperties/gproperties_z_unit_test.go +++ b/encoding/gproperties/gproperties_z_unit_test.go @@ -19,9 +19,13 @@ import ( var pStr string = ` # 模板引擎目录 viewpath = "/home/www/templates/" -# MySQL数据库配置 +# redis数据库配置 redis.disk = "127.0.0.1:6379,0" redis.cache = "127.0.0.1:6379,1" +#SQL配置 +sql.mysql.0.type = mysql +sql.mysql.0.ip = 127.0.0.1 +sql.mysql.0.user = root ` var errorTests = []struct { input, msg string @@ -114,4 +118,14 @@ func TestToJson(t *testing.T) { } t.Assert(jsonPr, expectJson) }) + gtest.C(t, func(t *gtest.T) { + for _, v := range errorTests { + _, err := gproperties.ToJson(([]byte)(v.input)) + if err == nil { + t.Errorf("encode should be failed. %v", err) + return + } + t.AssertIN(`Lib magiconair load Properties data failed.`, strings.Split(err.Error(), ":")) + } + }) }