From 7d1a508ea910a58e6039bab8ea82139028154ec9 Mon Sep 17 00:00:00 2001 From: John Guo Date: Sat, 12 Nov 2022 10:49:48 +0800 Subject: [PATCH] improve ut case for package gcache/gpool (#2290) * improve ut case for package gcache/gpool * up --- container/gpool/gpool_z_example_test.go | 2 +- os/gcache/gcache_z_unit_test.go | 1 + text/gstr/gstr_domain.go | 13 +++++++------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/container/gpool/gpool_z_example_test.go b/container/gpool/gpool_z_example_test.go index 1c0b8373e..fdfcd6be2 100644 --- a/container/gpool/gpool_z_example_test.go +++ b/container/gpool/gpool_z_example_test.go @@ -179,6 +179,6 @@ func ExamplePool_Close() { // wait for pool close time.Sleep(time.Second * 1) - // Output: + // May Output: // Close The Pool } diff --git a/os/gcache/gcache_z_unit_test.go b/os/gcache/gcache_z_unit_test.go index 73117834c..1ef5ef7ee 100644 --- a/os/gcache/gcache_z_unit_test.go +++ b/os/gcache/gcache_z_unit_test.go @@ -172,6 +172,7 @@ func TestCache_LRU(t *testing.T) { v, _ := cache.Get(ctx, 6) t.Assert(v, 6) time.Sleep(4 * time.Second) + g.Log().Debugf(ctx, `items after lru: %+v`, cache.MustData(ctx)) n, _ = cache.Size(ctx) t.Assert(n, 2) v, _ = cache.Get(ctx, 6) diff --git a/text/gstr/gstr_domain.go b/text/gstr/gstr_domain.go index 140c44d02..35b78d48c 100644 --- a/text/gstr/gstr_domain.go +++ b/text/gstr/gstr_domain.go @@ -17,13 +17,14 @@ func IsSubDomain(subDomain string, mainDomain string) bool { if p := strings.IndexByte(mainDomain, ':'); p != -1 { mainDomain = mainDomain[0:p] } - subArray := strings.Split(subDomain, ".") - mainArray := strings.Split(mainDomain, ".") - subLength := len(subArray) - mainLength := len(mainArray) - + var ( + subArray = strings.Split(subDomain, ".") + mainArray = strings.Split(mainDomain, ".") + subLength = len(subArray) + mainLength = len(mainArray) + ) // Eg: - // goframe.org is not sub-dome of 's.goframe.org' + // "goframe.org" is not sub-domain of "s.goframe.org". if mainLength > subLength { for i := range mainArray[0 : mainLength-subLength] { if mainArray[i] != "*" {