diff --git a/apier/v1/suppliers_it_test.go b/apier/v1/suppliers_it_test.go index 422a6655d..4ca445aba 100644 --- a/apier/v1/suppliers_it_test.go +++ b/apier/v1/suppliers_it_test.go @@ -989,7 +989,7 @@ func testV1SplSGetSupplierForEvent(t *testing.T) { Sorting: utils.MetaLC, SortingParameters: []string{}, Suppliers: []*engine.Supplier{ - &engine.Supplier{ + { ID: "supplier_1", FilterIDs: nil, AccountIDs: nil, @@ -1000,7 +1000,7 @@ func testV1SplSGetSupplierForEvent(t *testing.T) { Blocker: false, SupplierParameters: "", }, - &engine.Supplier{ + { ID: "supplier_2", FilterIDs: nil, AccountIDs: nil, diff --git a/config/apiercfg_test.go b/config/apiercfg_test.go index a81607a8d..1f80fdcc7 100644 --- a/config/apiercfg_test.go +++ b/config/apiercfg_test.go @@ -126,13 +126,13 @@ func TestApierCfgloadFromJsonCfg2(t *testing.T) { } exp := ApierCfg{ - Enabled: bl, - CachesConns: slc, - SchedulerConns: slc, + Enabled: bl, + CachesConns: slc, + SchedulerConns: slc, AttributeSConns: slc, } - err := a.loadFromJsonCfg(&js) + err := a.loadFromJsonCfg(&js) if err != nil { t.Fatal("was not expecting an error", err) @@ -149,9 +149,9 @@ func TestApierCfgAsMapInterface2(t *testing.T) { slc := []string{"val1", "val2"} a := ApierCfg{ - Enabled: bl, - CachesConns: slc, - SchedulerConns: slc, + Enabled: bl, + CachesConns: slc, + SchedulerConns: slc, AttributeSConns: slc, } @@ -162,7 +162,7 @@ func TestApierCfgAsMapInterface2(t *testing.T) { utils.AttributeSConnsCfg: slc, } - rcv := a.AsMapInterface() + rcv := a.AsMapInterface() if !reflect.DeepEqual(rcv, exp) { t.Errorf("recived %v, expected %v", rcv, exp) diff --git a/config/cachecfg_test.go b/config/cachecfg_test.go index 0aada864c..b4a72484d 100644 --- a/config/cachecfg_test.go +++ b/config/cachecfg_test.go @@ -120,7 +120,7 @@ func TestCacheCFGAsMapInterface(t *testing.T) { Limit: 1, TTL: 1 * time.Second, StaticTTL: true, - Precache: false, + Precache: false, } rcv := c.AsMapInterface() @@ -136,14 +136,12 @@ func TestCacheCFGAsMapInterface(t *testing.T) { } } - - func TestCacheCFGAddTmpCaches(t *testing.T) { c := CacheParamCfg{ Limit: 1, TTL: 1 * time.Second, StaticTTL: true, - Precache: false, + Precache: false, } cc := CacheCfg{"test": &c} @@ -166,7 +164,7 @@ func TestCacheCFGAsMappInterface(t *testing.T) { Limit: 1, TTL: 1 * time.Second, StaticTTL: true, - Precache: false, + Precache: false, } cc := CacheCfg{"test": &c} diff --git a/config/cdrscfg_test.go b/config/cdrscfg_test.go index 58e2fad17..afa494e06 100644 --- a/config/cdrscfg_test.go +++ b/config/cdrscfg_test.go @@ -234,7 +234,7 @@ func TestCdrsCfgAsMapInterface2(t *testing.T) { OnlineCDRExports: slc, } - exp := map[string]any { + exp := map[string]any{ utils.EnabledCfg: cdrscfg.Enabled, utils.ExtraFieldsCfg: []string{}, utils.StoreCdrsCfg: cdrscfg.StoreCdrs, diff --git a/config/config_json_test.go b/config/config_json_test.go index 4e622a833..b23ecc770 100644 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -1735,5 +1735,3 @@ func TestDfEventReaderCfg(t *testing.T) { t.Errorf("Expected: %+v, \nreceived: %+v", utils.ToJSON(eCfg), utils.ToJSON(cfg)) } } - - diff --git a/config/config_test.go b/config/config_test.go index 6ee0dcd62..23fb4b186 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -2177,4 +2177,4 @@ func TestConfigLoadErrors(t *testing.T) { t.Error("was expecting an error") } } -} \ No newline at end of file +} diff --git a/config/dispatchercfg_test.go b/config/dispatchercfg_test.go index ece33211b..feeb2c7f5 100644 --- a/config/dispatchercfg_test.go +++ b/config/dispatchercfg_test.go @@ -153,12 +153,12 @@ func TestDispatcherCfgloadFromJsonCfg(t *testing.T) { } exp := DispatcherSCfg{ - Enabled : bl, - IndexedSelects : bl, - StringIndexedFields : &slc, - PrefixIndexedFields : &slc, - AttributeSConns : slc, - NestedFields : bl, + Enabled: bl, + IndexedSelects: bl, + StringIndexedFields: &slc, + PrefixIndexedFields: &slc, + AttributeSConns: slc, + NestedFields: bl, } err := d.loadFromJsonCfg(&js) @@ -176,12 +176,12 @@ func TestDispatcherSCfgAsMapInterface2(t *testing.T) { slc := []string{"val1", "val2"} dsp := DispatcherSCfg{ - Enabled : bl, - IndexedSelects : bl, - StringIndexedFields : &slc, - PrefixIndexedFields : &slc, - AttributeSConns : slc, - NestedFields : bl, + Enabled: bl, + IndexedSelects: bl, + StringIndexedFields: &slc, + PrefixIndexedFields: &slc, + AttributeSConns: slc, + NestedFields: bl, } exp := map[string]any{ diff --git a/config/erscfg_test.go b/config/erscfg_test.go index a39c99b03..fbc48f4bc 100644 --- a/config/erscfg_test.go +++ b/config/erscfg_test.go @@ -333,7 +333,7 @@ func TestERsCfgAsMapInterface(t *testing.T) { func TestERSCFGClone(t *testing.T) { ev := EventReaderCfg{ - CacheDumpFields: []*FCTemplate{ + CacheDumpFields: []*FCTemplate{ {Tag: "test"}, }, } diff --git a/config/generalcfg_test.go b/config/generalcfg_test.go index 3a6418109..65aec217c 100644 --- a/config/generalcfg_test.go +++ b/config/generalcfg_test.go @@ -191,10 +191,10 @@ func TestGeneralCfgloadFromJsonCfgErrors(t *testing.T) { strErr := "test" g := GeneralCfg{} - tests := []struct{ - name string - arg *GeneralJsonCfg - err string + tests := []struct { + name string + arg *GeneralJsonCfg + err string }{ { name: "Connect timeout error check", diff --git a/config/httpcfg_test.go b/config/httpcfg_test.go index 7e5ec02c8..6a9f5db98 100644 --- a/config/httpcfg_test.go +++ b/config/httpcfg_test.go @@ -126,4 +126,4 @@ func TestHTTPCfgAsMapInterface2(t *testing.T) { if !reflect.DeepEqual(rcv, exp) { t.Errorf("Expected: %+v ,\n received: %+v", exp, rcv) } -} \ No newline at end of file +} diff --git a/config/loaderscfg_test.go b/config/loaderscfg_test.go index c5ddef7ed..c2cf6cbbf 100644 --- a/config/loaderscfg_test.go +++ b/config/loaderscfg_test.go @@ -193,20 +193,20 @@ func TestLoadersCFGEnable(t *testing.T) { lst := LoaderSCfgs{<} lsf := LoaderSCfgs{&lf} - tests := []struct{ - name string - loader LoaderSCfgs - exp bool + tests := []struct { + name string + loader LoaderSCfgs + exp bool }{ { - name: "return true", + name: "return true", loader: lst, - exp: true, + exp: true, }, { - name: "return false", + name: "return false", loader: lsf, - exp: false, + exp: false, }, } @@ -232,30 +232,30 @@ func TestLoadersCFGLoadFromJsonCfg(t *testing.T) { str := "`test" ljd := LoaderJsonDataType{ - Fields: &[]*FcTemplateJsonCfg{ - {Value: &str,}, + Fields: &[]*FcTemplateJsonCfg{ + {Value: &str}, }, } type args struct { - jsnCfg *LoaderJsonDataType + jsnCfg *LoaderJsonDataType separator string } - tests := []struct{ - name string - args args - exp error + tests := []struct { + name string + args args + exp error }{ { name: "nil return", args: args{jsnCfg: nil, separator: ""}, - exp: nil, + exp: nil, }, { name: "error check", args: args{&ljd, ""}, - exp: fmt.Errorf("Unclosed unspilit syntax"), + exp: fmt.Errorf("Unclosed unspilit syntax"), }, } diff --git a/config/objdp_test.go b/config/objdp_test.go index 85bb0af9a..6b40cd7b7 100644 --- a/config/objdp_test.go +++ b/config/objdp_test.go @@ -46,7 +46,7 @@ func TestObjDPNewObjectDP(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - + rcv := NewObjectDP(tt.args.obj, tt.args.prfxSlc) if rcv.String() != tt.exp.String() { @@ -59,12 +59,12 @@ func TestObjDPNewObjectDP(t *testing.T) { func TestObjDPSetCache(t *testing.T) { type args struct { - path string - val any + path string + val any } - tests := []struct{ - name string + tests := []struct { + name string args args }{ { @@ -79,7 +79,7 @@ func TestObjDPSetCache(t *testing.T) { odp := ObjectDP{"test", map[string]any{}, []string{}} odp.setCache(tt.args.path, tt.args.val) - + if odp.cache["test"] != "val1" { t.Error("didn't set cache") } @@ -88,21 +88,21 @@ func TestObjDPSetCache(t *testing.T) { } func TestObjDPGetCache(t *testing.T) { - + type exp struct { val any - has bool + has bool } - tests := []struct{ + tests := []struct { name string - arg string - exp exp + arg string + exp exp }{ { name: "get cache", - arg: "test", - exp: exp{val: "val1", has: true}, + arg: "test", + exp: exp{val: "val1", has: true}, }, } @@ -116,12 +116,12 @@ func TestObjDPGetCache(t *testing.T) { if !has { t.Error("didn't get cache") - } + } if rcv != tt.exp.val { t.Errorf("recived %s, expected %s", rcv, tt.exp.val) } - + }) } } @@ -133,50 +133,50 @@ func TestObjDPFieldAsInterface(t *testing.T) { odp.setCache("test", "val1") type exp struct { - data any - err bool + data any + err bool } - tests := []struct{ - name string - arg []string - exp exp + tests := []struct { + name string + arg []string + exp exp slcPrfx []string }{ { - name: "found in cache", - arg: []string{"test"}, - exp: exp{data: "val1", err: false}, + name: "found in cache", + arg: []string{"test"}, + exp: exp{data: "val1", err: false}, slcPrfx: []string{"!", "."}, }, { - name: "object has prefix slice and length of field pat his smaller than lenght of prefix slice", - arg: []string{"test1"}, - exp: exp{data: nil, err: true}, + name: "object has prefix slice and length of field pat his smaller than lenght of prefix slice", + arg: []string{"test1"}, + exp: exp{data: nil, err: true}, slcPrfx: []string{"!", "."}, }, { - name: "has slice prefix different from field path", - arg: []string{"test1", "test2"}, - exp: exp{data: nil, err: true}, + name: "has slice prefix different from field path", + arg: []string{"test1", "test2"}, + exp: exp{data: nil, err: true}, slcPrfx: []string{"!", "."}, }, { - name: "has slice prefix", - arg: []string{"!", "."}, - exp: exp{data: nil, err: false}, + name: "has slice prefix", + arg: []string{"!", "."}, + exp: exp{data: nil, err: false}, slcPrfx: []string{"!", "."}, }, { - name: "has selector with error", - arg: []string{"test[0", "."}, - exp: exp{data: nil, err: true}, + name: "has selector with error", + arg: []string{"test[0", "."}, + exp: exp{data: nil, err: true}, slcPrfx: []string{}, }, { - name: "has selector", - arg: []string{"test[0]", "."}, - exp: exp{data: nil, err: true}, + name: "has selector", + arg: []string{"test[0]", "."}, + exp: exp{data: nil, err: true}, slcPrfx: []string{}, }, } @@ -207,24 +207,24 @@ func TestObjDPFieldAsInterface(t *testing.T) { func TestObjDPFieldAsString(t *testing.T) { type exp struct { - data string - err bool + data string + err bool } - tests := []struct{ + tests := []struct { name string args []string - exp exp + exp exp }{ { name: "error", args: []string{"123"}, - exp: exp{data: "", err: true}, + exp: exp{data: "", err: true}, }, { name: "error", args: []string{}, - exp: exp{data: "", err: false}, + exp: exp{data: "", err: false}, }, } diff --git a/config/schedulercfg_test.go b/config/schedulercfg_test.go index c6b943cbc..4f8509789 100644 --- a/config/schedulercfg_test.go +++ b/config/schedulercfg_test.go @@ -85,25 +85,25 @@ func TestSchedulerCfgAsMapInterface(t *testing.T) { func TestSchedulerCfgloadFromJsonCfg2(t *testing.T) { s := SchedulerCfg{} - tests := []struct{ + tests := []struct { name string - arg *SchedulerJsonCfg - err string + arg *SchedulerJsonCfg + err string }{ { name: "cdrs conns diff from *internal", - arg: &SchedulerJsonCfg{Cdrs_conns: &[]string{"test"}}, - err: "", + arg: &SchedulerJsonCfg{Cdrs_conns: &[]string{"test"}}, + err: "", }, { name: "cdrs conns equal to *internal", - arg: &SchedulerJsonCfg{Cdrs_conns: &[]string{"*internal"}}, - err: "", + arg: &SchedulerJsonCfg{Cdrs_conns: &[]string{"*internal"}}, + err: "", }, { name: "filers with value", - arg: &SchedulerJsonCfg{Filters: &[]string{"test"}}, - err: "", + arg: &SchedulerJsonCfg{Filters: &[]string{"test"}}, + err: "", }, } diff --git a/config/slicedp_test.go b/config/slicedp_test.go index 7cbf90cd6..0f9ca5e6e 100644 --- a/config/slicedp_test.go +++ b/config/slicedp_test.go @@ -55,7 +55,7 @@ func TestSliceDPFieldAsInterface(t *testing.T) { slc2 := []string{"0"} slc3 := []string{"test"} slc4 := []string{"4"} - cp := SliceDP{req:slc2, cache: utils.MapStorage{"0": "val1"}} + cp := SliceDP{req: slc2, cache: utils.MapStorage{"0": "val1"}} type exp struct { data any @@ -103,7 +103,7 @@ func TestSliceDPFieldAsInterface(t *testing.T) { t.Fatal("was expecting an error") } } else { - if !reflect.DeepEqual(err, tt.exp.err) { + if !reflect.DeepEqual(err, tt.exp.err) { t.Fatalf("recived %s, expected %s", err, tt.exp.err) } } @@ -118,7 +118,7 @@ func TestSliceDPFieldAsInterface(t *testing.T) { slcRec := []string{"0", "1"} slcArg := []string{"0"} - cp := SliceDP{req:slcRec, cache: utils.MapStorage{"test": "val1"}} + cp := SliceDP{req: slcRec, cache: utils.MapStorage{"test": "val1"}} data, err := cp.FieldAsInterface(slcArg) @@ -134,29 +134,29 @@ func TestSliceDPFieldAsInterface(t *testing.T) { } func TestSliceDPFieldAsString(t *testing.T) { - + slc := []string{"0", "1"} cP := NewSliceDP(slc) type exp struct { - data string - err error + data string + err error } - tests := []struct{ + tests := []struct { name string - arg []string - exp exp + arg []string + exp exp }{ { name: "err", - arg: []string{"2"}, - exp: exp{"", utils.ErrNotFound}, + arg: []string{"2"}, + exp: exp{"", utils.ErrNotFound}, }, { name: "no err", - arg: []string{"1"}, - exp: exp{"1", nil}, + arg: []string{"1"}, + exp: exp{"1", nil}, }, } @@ -167,7 +167,7 @@ func TestSliceDPFieldAsString(t *testing.T) { if err != tt.exp.err { t.Fatalf("recived %s, expected %s", err, tt.exp.err) } - + if !reflect.DeepEqual(data, tt.exp.data) { t.Errorf("recived %v, expected %v", data, tt.exp.data) } @@ -176,7 +176,7 @@ func TestSliceDPFieldAsString(t *testing.T) { } func TestSliceDPRemoteHost(t *testing.T) { - + slc := []string{"test", "test2"} cP := NewSliceDP(slc) diff --git a/config/smconfig_test.go b/config/smconfig_test.go index 79912f379..836072290 100644 --- a/config/smconfig_test.go +++ b/config/smconfig_test.go @@ -633,4 +633,4 @@ func TestSMConfigGetDefaultUsage(t *testing.T) { if rcv != exp { t.Errorf("received %v, expected %v", rcv, exp) } -} \ No newline at end of file +} diff --git a/engine/filters_test.go b/engine/filters_test.go index 7586d26bd..729e78e3b 100644 --- a/engine/filters_test.go +++ b/engine/filters_test.go @@ -2792,8 +2792,8 @@ func TestFilterspassStringPrefix(t *testing.T) { t.Error("Recived:", rcv) } - f2 := FilterRule { - Values: []string{"~test.test"}, + f2 := FilterRule{ + Values: []string{"~test.test"}, } rcv, err = f2.passStringPrefix(utils.MapStorage{"test": "test"}, []utils.DataProvider{utils.MapStorage{"test": "test"}}) @@ -2826,8 +2826,8 @@ func TestFilterspassStringSuffix(t *testing.T) { t.Error("Recived:", rcv) } - f2 := FilterRule { - Values: []string{"~test.test"}, + f2 := FilterRule{ + Values: []string{"~test.test"}, } rcv, err = f2.passStringSuffix(utils.MapStorage{"test": "test"}, []utils.DataProvider{utils.MapStorage{"test": "test"}}) @@ -2991,4 +2991,4 @@ func TestFilterspassEqualTo(t *testing.T) { if rcv != false { t.Error("Recived:", rcv) } -} \ No newline at end of file +} diff --git a/engine/storage_test.go b/engine/storage_test.go index bb3e9c8bb..9ebbeca3c 100644 --- a/engine/storage_test.go +++ b/engine/storage_test.go @@ -1637,13 +1637,13 @@ func TestStorageUtilsNewStorDBConn(t *testing.T) { type args struct { dbType, host, port, name, user, pass, marshaler, sslmode string - maxConn, maxIdleConn, connMaxLifetime int - stringIndexedFields, prefixIndexedFields []string - itemsCacheCfg map[string]*config.ItemOpt + maxConn, maxIdleConn, connMaxLifetime int + stringIndexedFields, prefixIndexedFields []string + itemsCacheCfg map[string]*config.ItemOpt } type exp struct { - db StorDB + db StorDB err string } @@ -1651,43 +1651,43 @@ func TestStorageUtilsNewStorDBConn(t *testing.T) { db2, err2 := NewPostgresStorage("1", "1", "1", str, str, str, 1, 1, 1) db3, err3 := NewMySQLStorage("1", "1", "1", str, str, 1, 1, 1) - tests := []struct{ - name string - args args - exp exp + tests := []struct { + name string + args args + exp exp }{ { name: "case mongo", args: args{"*mongo", "1", "1", "1", str, str, str, str, 1, 1, 1, []string{"test"}, []string{"test2"}, map[string]*config.ItemOpt{}}, - exp: exp{db, err.Error()}, + exp: exp{db, err.Error()}, }, { name: "case postgres", args: args{"*postgres", "1", "1", "1", str, str, str, str, 1, 1, 1, []string{"test"}, []string{"test2"}, map[string]*config.ItemOpt{}}, - exp: exp{db2, err2.Error()}, + exp: exp{db2, err2.Error()}, }, { name: "case MySQL", args: args{"*mysql", "1", "1", "1", str, str, str, str, 1, 1, 1, []string{"test"}, []string{"test2"}, map[string]*config.ItemOpt{}}, - exp: exp{db3, err3.Error()}, + exp: exp{db3, err3.Error()}, }, { name: "case default", args: args{"test", "1", "1", "1", str, str, str, str, 1, 1, 1, []string{"test"}, []string{"test2"}, map[string]*config.ItemOpt{}}, - exp: exp{nil, "unknown db 'test' valid options are [*mysql, *mongo, *postgres, *internal]"}, + exp: exp{nil, "unknown db 'test' valid options are [*mysql, *mongo, *postgres, *internal]"}, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { rcv, err := NewStorDBConn(tt.args.dbType, tt.args.host, tt.args.port, tt.args.name, tt.args.user, - tt.args.pass, tt.args.marshaler, tt.args.sslmode, tt.args.maxConn, - tt.args.maxIdleConn, tt.args.connMaxLifetime, tt.args.stringIndexedFields, - tt.args.prefixIndexedFields, tt.args.itemsCacheCfg) - + tt.args.pass, tt.args.marshaler, tt.args.sslmode, tt.args.maxConn, + tt.args.maxIdleConn, tt.args.connMaxLifetime, tt.args.stringIndexedFields, + tt.args.prefixIndexedFields, tt.args.itemsCacheCfg) + if err.Error() != tt.exp.err { t.Error(err) - } + } if !reflect.DeepEqual(rcv, tt.exp.db) { t.Errorf("received %v, expected %v", rcv, tt.exp.db) diff --git a/utils/dataprovider_test.go b/utils/dataprovider_test.go index 3ad9aa290..b2a0609e6 100644 --- a/utils/dataprovider_test.go +++ b/utils/dataprovider_test.go @@ -145,8 +145,7 @@ func TestDPComposeNavMapVal(t *testing.T) { } onm = NewOrderedNavigableMap() - nm = NavigableMap2{ - } + nm = NavigableMap2{} if err := ComposeNavMapVal(onm, &FullPath{Path: "Field", PathItems: PathItems{}}, NewNMData(18)); err == nil { t.Error("was expecting an error") } diff --git a/utils/json_codec_test.go b/utils/json_codec_test.go index 4596c33ff..67311a1e9 100644 --- a/utils/json_codec_test.go +++ b/utils/json_codec_test.go @@ -261,7 +261,6 @@ func TestJSONReadRequestBody3(t *testing.T) { } } - /* - NewCustomJSONServerCodec - defer Close @@ -282,7 +281,6 @@ func TestJSONCodecOK(t *testing.T) { s := NewCustomJSONServerCodec(conn) c := s.(*jsonServerCodec) - defer s.Close() //ReadRequesHeader @@ -355,9 +353,9 @@ func TestJSONCodecOK(t *testing.T) { t.Error(err) } - if mp["error"] != nil || - mp["result"] != "test" || - mp["id"] != 0. { + if mp["error"] != nil || + mp["result"] != "test" || + mp["id"] != 0. { t.Error("unexpected reply", mp) } } @@ -406,8 +404,8 @@ func TestJSONCodecWriteResponse2(t *testing.T) { } res := rpc.Response{ - Seq: 1, - Error: "error", + Seq: 1, + Error: "error", } err = c.WriteResponse(&res, "test") if err != nil { @@ -420,9 +418,9 @@ func TestJSONCodecWriteResponse2(t *testing.T) { t.Error(err) } - if mp["error"] != "error" || - mp["result"] != nil || - mp["id"] != nil { + if mp["error"] != "error" || + mp["result"] != nil || + mp["id"] != nil { t.Error("unexpected reply", mp) } } diff --git a/utils/map_test.go b/utils/map_test.go index 366e7dcbd..ce74a9c6e 100644 --- a/utils/map_test.go +++ b/utils/map_test.go @@ -104,9 +104,9 @@ func TestMapKeys(t *testing.T) { func TestMapNewStringMap(t *testing.T) { tests := []struct { - name string - args []string - want StringMap + name string + args []string + want StringMap }{ { name: "testing both return cases", @@ -180,29 +180,28 @@ func TestMapEqual(t *testing.T) { }{ { name: "sm is nil and argument is not nil", - sm: nil, + sm: nil, args: StringMap{"test": false}, want: false, }, { name: "different lengths", - sm: StringMap{"test1": true, "test2": true}, + sm: StringMap{"test1": true, "test2": true}, args: StringMap{"test1": true}, want: false, }, { name: "different values", - sm: StringMap{"test1": true}, + sm: StringMap{"test1": true}, args: StringMap{"test1": false}, want: false, }, { name: "same keys and values are true", - sm: StringMap{"test": true, "test1": true}, + sm: StringMap{"test": true, "test1": true}, args: StringMap{"test": true, "test1": true}, want: true, }, - } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -222,19 +221,19 @@ func TestMapIncludes(t *testing.T) { }{ { name: "different lengths", - sm: StringMap{"test": false}, + sm: StringMap{"test": false}, args: StringMap{"test": false, "test1": true}, want: false, }, { name: "sm does not have all the keys of the argument", - sm: StringMap{"test": true, "test1": true}, + sm: StringMap{"test": true, "test1": true}, args: StringMap{"test2": true, "test3": false}, want: false, }, { name: "sm contains all the keys of the argument", - sm: StringMap{"test": true, "test1": true, "test2": true}, + sm: StringMap{"test": true, "test1": true, "test2": true}, args: StringMap{"test": true, "test1": true}, want: true, }, @@ -256,7 +255,7 @@ func TestMapSlice(t *testing.T) { }{ { name: "testing Slice", - sm: StringMap{"test1": true, "test2": true, "test3": false}, + sm: StringMap{"test1": true, "test2": true, "test3": false}, want: []string{"test1", "test2", "test3"}, }, } @@ -280,17 +279,17 @@ func TestMapStringMap_Copy(t *testing.T) { }{ { name: "testing Copy", - sm: StringMap{}, + sm: StringMap{}, args: StringMap{"test1": false, "test2": true}, }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - tt.sm.Copy(tt.args) - if !reflect.DeepEqual(tt.sm, tt.args) { - t.Errorf("sm %v, want %v", tt.sm, tt.args) - } - }) + t.Run(tt.name, func(t *testing.T) { + tt.sm.Copy(tt.args) + if !reflect.DeepEqual(tt.sm, tt.args) { + t.Errorf("sm %v, want %v", tt.sm, tt.args) + } + }) } } @@ -302,7 +301,7 @@ func TestMapClone(t *testing.T) { }{ { name: "testinf Clone", - sm: StringMap{"test1": true, "test2": false}, + sm: StringMap{"test1": true, "test2": false}, want: StringMap{"test1": true, "test2": false}, }, } @@ -310,7 +309,7 @@ func TestMapClone(t *testing.T) { t.Run(tt.name, func(t *testing.T) { if got := tt.sm.Clone(); !reflect.DeepEqual(got, tt.want) { t.Errorf("StringMap.Clone() = %v, want %v", got, tt.want) - } + } }) } } @@ -323,19 +322,19 @@ func TestMapGetOne(t *testing.T) { }{ { name: "empty StringMap", - sm: StringMap{}, + sm: StringMap{}, want: EmptyString, }, { name: "StringMap with values", - sm: StringMap{"test1": true}, + sm: StringMap{"test1": true}, want: "test1", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := tt.sm.GetOne(); got != tt.want { - t.Errorf("StringMap.GetOne() = %v, want %v", got, tt.want) + t.Errorf("StringMap.GetOne() = %v, want %v", got, tt.want) } }) } @@ -350,7 +349,7 @@ func TestMapJoin(t *testing.T) { }{ { name: "testing Join", - sm: StringMap{"test1": true, "test2": true}, + sm: StringMap{"test1": true, "test2": true}, args: []StringMap{{"test3": false, "test4": true}, {"test5": true}}, want: StringMap{"test1": true, "test2": true, "test3": false, "test4": true, "test5": true}, }, @@ -358,23 +357,23 @@ func TestMapJoin(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tt.sm.Join(tt.args...) - if !reflect.DeepEqual(tt.sm, tt.want) { + if !reflect.DeepEqual(tt.sm, tt.want) { t.Errorf("sm %v, want %v", tt.sm, tt.want) - } + } }) } } func TestMapString(t *testing.T) { tests := []struct { - name string - sm StringMap + name string + sm StringMap want1 string want2 string }{ { - name: "testing string", - sm: StringMap{"test1": true, "test2": false}, + name: "testing string", + sm: StringMap{"test1": true, "test2": false}, want1: "test1;test2", want2: "test2;test1", }, @@ -382,7 +381,7 @@ func TestMapString(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if got := tt.sm.String(); got != tt.want1 && got != tt.want2 { - t.Errorf("StringMap.String() = %v", got) + t.Errorf("StringMap.String() = %v", got) } }) } @@ -395,38 +394,38 @@ func TestMapFieldMultiplyFactorClone(t *testing.T) { wantCln FieldMultiplyFactor }{ { - name: "testing FieldMultiplyFactor.Clone", - fmp: FieldMultiplyFactor{"test": 0.5, "test2": 1.2}, + name: "testing FieldMultiplyFactor.Clone", + fmp: FieldMultiplyFactor{"test": 0.5, "test2": 1.2}, wantCln: FieldMultiplyFactor{"test": 0.5, "test2": 1.2}, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { if gotCln := tt.fmp.Clone(); !reflect.DeepEqual(gotCln, tt.wantCln) { - t.Errorf("FieldMultiplyFactor.Clone() = %v, want %v", gotCln, tt.wantCln) + t.Errorf("FieldMultiplyFactor.Clone() = %v, want %v", gotCln, tt.wantCln) } }) } } func TestMapStringToInt64(t *testing.T) { - tests := []struct{ + tests := []struct { name string args map[string]string want map[string]int64 - err bool + err bool }{ { name: "testing MapToStringInt64", args: map[string]string{"test": "1", "test2": "4"}, want: map[string]int64{"test": 1, "test2": 4}, - err: false, + err: false, }, { name: "passing invalid string value", args: map[string]string{"test": "abc"}, want: nil, - err: true, + err: true, }, } diff --git a/utils/mapstorage.go b/utils/mapstorage.go index 61bd9a7ac..07eb1c62a 100644 --- a/utils/mapstorage.go +++ b/utils/mapstorage.go @@ -42,8 +42,6 @@ type MapStorage map[string]any // String returns the map as json string func (ms MapStorage) String() string { return ToJSON(ms) } - - // FieldAsInterface returns the value from the path func (ms MapStorage) FieldAsInterface(fldPath []string) (val any, err error) { if len(fldPath) == 0 { diff --git a/utils/mapstorage_test.go b/utils/mapstorage_test.go index 943c2d649..39e14b884 100644 --- a/utils/mapstorage_test.go +++ b/utils/mapstorage_test.go @@ -240,16 +240,16 @@ func TestNavMapGetField(t *testing.T) { func TestMapStorageNavMapFieldAsInterface(t *testing.T) { nm := MapStorage{ "SlcString": []string{"val1", "val2"}, - "SlcAny": []any{"val1"}, - "MapPtr": &map[string]any{"test1": 1}, - "Array": [1]string{"val1"}, - "DP": MapStorage{"test": "val1"}, - "MapInt": map[string]int{"test": 1}, - "SlcDP": []DataProvider{MapStorage{"test": "val1"}}, - "SlcMS": []MapStorage{{"test": "val1"}}, + "SlcAny": []any{"val1"}, + "MapPtr": &map[string]any{"test1": 1}, + "Array": [1]string{"val1"}, + "DP": MapStorage{"test": "val1"}, + "MapInt": map[string]int{"test": 1}, + "SlcDP": []DataProvider{MapStorage{"test": "val1"}}, + "SlcMS": []MapStorage{{"test": "val1"}}, "SlcMapAny": []map[string]any{{"test": "val1"}}, "SlcAnyMap": []any{map[string]any{"test": "val1"}}, - "SlcAnyDP": []any{MapStorage{"test": "val1"}}, + "SlcAnyDP": []any{MapStorage{"test": "val1"}}, } type exp struct { @@ -269,83 +269,83 @@ func TestMapStorageNavMapFieldAsInterface(t *testing.T) { }, { name: "field is slice of strings, index not found", - arg: []string{"SlcString[3]"}, - exp: exp{nil, ErrNotFound}, + arg: []string{"SlcString[3]"}, + exp: exp{nil, ErrNotFound}, }, { name: "field is slice of strings", - arg: []string{"SlcString[1]"}, - exp: exp{"val2", nil}, + arg: []string{"SlcString[1]"}, + exp: exp{"val2", nil}, }, { name: "field is slice of any", - arg: []string{"SlcAny[1]"}, - exp: exp{nil, ErrNotFound}, + arg: []string{"SlcAny[1]"}, + exp: exp{nil, ErrNotFound}, }, { name: "not slice or array and ptr", - arg: []string{"MapPtr[1]"}, - exp: exp{nil, ErrNotFound}, + arg: []string{"MapPtr[1]"}, + exp: exp{nil, ErrNotFound}, }, { name: "array", - arg: []string{"Array[1]"}, - exp: exp{nil, ErrNotFound}, + arg: []string{"Array[1]"}, + exp: exp{nil, ErrNotFound}, }, { name: "array", - arg: []string{"Array[0]"}, - exp: exp{"val1", nil}, + arg: []string{"Array[0]"}, + exp: exp{"val1", nil}, }, { name: "data storage", - arg: []string{"DP","test"}, - exp: exp{"val1", nil}, + arg: []string{"DP", "test"}, + exp: exp{"val1", nil}, }, { name: "map of int", - arg: []string{"MapInt","test"}, - exp: exp{map[string]int{"test": 1}, ErrWrongPath}, + arg: []string{"MapInt", "test"}, + exp: exp{map[string]int{"test": 1}, ErrWrongPath}, }, { name: "slice of DataProvider not found", - arg: []string{"SlcDP[1]", "test"}, - exp: exp{nil, ErrNotFound}, + arg: []string{"SlcDP[1]", "test"}, + exp: exp{nil, ErrNotFound}, }, { name: "slice of DataProvider", - arg: []string{"SlcDP[0]", "test"}, - exp: exp{"val1", nil}, + arg: []string{"SlcDP[0]", "test"}, + exp: exp{"val1", nil}, }, { name: "slice of MapStorage not found", - arg: []string{"SlcMS[1]", "test"}, - exp: exp{nil, ErrNotFound}, + arg: []string{"SlcMS[1]", "test"}, + exp: exp{nil, ErrNotFound}, }, { name: "slice of MapStorage", - arg: []string{"SlcMS[0]", "test"}, - exp: exp{"val1", nil}, + arg: []string{"SlcMS[0]", "test"}, + exp: exp{"val1", nil}, }, { name: "slice of map[string]any not found", - arg: []string{"SlcMapAny[1]", "test"}, - exp: exp{nil, ErrNotFound}, + arg: []string{"SlcMapAny[1]", "test"}, + exp: exp{nil, ErrNotFound}, }, { name: "slice of any", - arg: []string{"SlcAnyMap[1]", "test"}, - exp: exp{nil, ErrNotFound}, + arg: []string{"SlcAnyMap[1]", "test"}, + exp: exp{nil, ErrNotFound}, }, { name: "slice of any map", - arg: []string{"SlcAnyMap[0]", "test"}, - exp: exp{"val1", nil}, + arg: []string{"SlcAnyMap[0]", "test"}, + exp: exp{"val1", nil}, }, { name: "slice of any data provider", - arg: []string{"SlcAnyDP[0]", "test"}, - exp: exp{"val1", nil}, + arg: []string{"SlcAnyDP[0]", "test"}, + exp: exp{"val1", nil}, }, } @@ -502,7 +502,7 @@ func TestMapStorageGetPathFromValue(t *testing.T) { { name: "map", args: args{reflect.ValueOf(map[string]string{"test": "test"}), "test"}, - exp: []string{"testtest"}, + exp: []string{"testtest"}, }, { name: "struct", diff --git a/utils/orderednavigablemap_test.go b/utils/orderednavigablemap_test.go index 358ee7938..ed4270acf 100644 --- a/utils/orderednavigablemap_test.go +++ b/utils/orderednavigablemap_test.go @@ -750,14 +750,14 @@ func TestOrderedNavigableRemote(t *testing.T) { func TestONMRemoveAll(t *testing.T) { p := PathItemList{ root: PathItemElement{}, - len: 0, + len: 0, } onm := OrderedNavigableMap{ - nm: &NMData{"test"}, + nm: &NMData{"test"}, orderIdx: &p, orderRef: map[string][]*PathItemElement{}, } - + onm.RemoveAll() if onm.nm.String() != "{}" { diff --git a/utils/pathitem_test.go b/utils/pathitem_test.go index 3f101fd39..d18703cde 100644 --- a/utils/pathitem_test.go +++ b/utils/pathitem_test.go @@ -221,5 +221,3 @@ func TestPathItemGetPathWithoutIndex(t *testing.T) { }) } } - - diff --git a/utils/slice_test.go b/utils/slice_test.go index 22d1fe445..b846b0ea4 100644 --- a/utils/slice_test.go +++ b/utils/slice_test.go @@ -104,7 +104,7 @@ func TestSliceAvgNegative(t *testing.T) { }, { name: "testing AvgNegative", - args: []float64{-1,0,4}, + args: []float64{-1, 0, 4}, want: 1, }, } @@ -119,26 +119,26 @@ func TestSliceAvgNegative(t *testing.T) { func TestSliceAPrefixSliceItems(t *testing.T) { type args struct { - slc []string - prfx string + slc []string + prfx string } tests := []struct { - name string - args args - wantOut []string + name string + args args + wantOut []string }{ - { - name: "testing PrefixSliceItems", - args: args{[]string{"test1", "test2"}, "!"}, - wantOut: []string{"!test1", "!test2"}, - }, + { + name: "testing PrefixSliceItems", + args: args{[]string{"test1", "test2"}, "!"}, + wantOut: []string{"!test1", "!test2"}, + }, } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if gotOut := PrefixSliceItems(tt.args.slc, tt.args.prfx); !reflect.DeepEqual(gotOut, tt.wantOut) { - t.Errorf("PrefixSliceItems() = %v, want %v", gotOut, tt.wantOut) - } - }) + t.Run(tt.name, func(t *testing.T) { + if gotOut := PrefixSliceItems(tt.args.slc, tt.args.prfx); !reflect.DeepEqual(gotOut, tt.wantOut) { + t.Errorf("PrefixSliceItems() = %v, want %v", gotOut, tt.wantOut) + } + }) } } diff --git a/utils/struct_test.go b/utils/struct_test.go index 709dda841..1e5356569 100644 --- a/utils/struct_test.go +++ b/utils/struct_test.go @@ -173,15 +173,15 @@ func TestMissingMapFields(t *testing.T) { func TestStructToMapStringString(t *testing.T) { - tests := []struct{ + tests := []struct { name string - arg any - exp map[string]string + arg any + exp map[string]string }{ { name: "struct to map", - arg: &struct{ - name string + arg: &struct { + name string surname string }{"test", "test2"}, exp: map[string]string{"name": "test", "surname": "test2"}, @@ -206,19 +206,19 @@ func TestStructGetMapExtraFields(t *testing.T) { } type args struct { - in any + in any extraFields string } - tests := []struct{ + tests := []struct { name string args args - exp map[string]string + exp map[string]string }{ { name: "tests get map extra fields", args: args{&in{map[string]string{"test": "val1"}}, "mapAny"}, - exp: map[string]string{"test": "val1"}, + exp: map[string]string{"test": "val1"}, }, } @@ -238,13 +238,13 @@ func TestStructSetMapExtraFields(t *testing.T) { type in struct { Field map[string]string } - + type args struct { - Values map[string]string + Values map[string]string extraFields string } - tests := []struct{ + tests := []struct { name string args args }{ @@ -257,8 +257,7 @@ func TestStructSetMapExtraFields(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { argIn := in{map[string]string{"test": "val1"}} - SetMapExtraFields(&argIn , tt.args.Values, tt.args.extraFields) - + SetMapExtraFields(&argIn, tt.args.Values, tt.args.extraFields) if argIn.Field["test"] != "" { t.Errorf("map value didn't change: %s, expected %s", argIn.Field["test"], tt.args.Values["test"]) @@ -270,7 +269,7 @@ func TestStructSetMapExtraFields(t *testing.T) { func TestStructFromMapStringString(t *testing.T) { type args struct { - m map[string]string + m map[string]string in any } @@ -280,15 +279,15 @@ func TestStructFromMapStringString(t *testing.T) { inArg := in{""} - tests := []struct{ + tests := []struct { name string args args - exp in + exp in }{ { name: "test map string string", args: args{map[string]string{"Field": ""}, &inArg}, - exp: in{Field: ""}, + exp: in{Field: ""}, }, } @@ -308,7 +307,7 @@ func TestStructFromMapStringString(t *testing.T) { func TestStructFromMapStringInterface(t *testing.T) { type args struct { - m map[string]any + m map[string]any in any } @@ -324,25 +323,25 @@ func TestStructFromMapStringInterface(t *testing.T) { inC := inCantSet{""} - tests := []struct{ + tests := []struct { name string args args - exp error + exp error }{ { name: "test from map string interface", args: args{map[string]any{"Field": ""}, &inArg}, - exp: nil, + exp: nil, }, { name: "test from map string interface", args: args{map[string]any{"Field": 1}, &inArg}, - exp: nil, + exp: nil, }, { name: "invalid field", args: args{map[string]any{"field": 1}, &inC}, - exp: nil, + exp: nil, }, } @@ -354,11 +353,11 @@ func TestStructFromMapStringInterface(t *testing.T) { if i == 1 { if err == nil { t.Error("was expecting an error") - } + } } else { if err != tt.exp { t.Errorf("recived %s, expected %s", err, tt.exp) - } + } } }) } @@ -380,26 +379,26 @@ func TestStructUpdateStructWithStrMap(t *testing.T) { m map[string]string } - tests := []struct{ + tests := []struct { name string args args - exp []string + exp []string }{ { name: "bool case", args: args{&arg, map[string]string{"Field1": "true", "Field2": "2", "Field3": "val2"}}, - exp: []string{}, + exp: []string{}, }, { name: "bool case", args: args{&arg, map[string]string{"Field": "1.8"}}, - exp: []string{"Field"}, + exp: []string{"Field"}, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - + rcv := UpdateStructWithStrMap(tt.args.s, tt.args.m) if !reflect.DeepEqual(rcv, tt.exp) {