From b7da1fc0c1cc8205f93682368e4706274e4c2751 Mon Sep 17 00:00:00 2001 From: xh3b4sd Date: Wed, 11 Oct 2023 23:56:37 +0200 Subject: [PATCH] update redigo and restructure (#22) --- engine/engine_balance_redis_test.go | 16 ++---- engine/engine_create_redis_test.go | 44 ++++------------ engine/engine_delete_redis_test.go | 16 ++---- engine/engine_exists_redis_test.go | 16 ++---- engine/engine_expire_redis_test.go | 16 ++---- engine/engine_extend_redis_test.go | 16 ++---- engine/engine_lifecycle_redis_test.go | 74 ++++++--------------------- engine/engine_lister_redis_test.go | 16 ++---- engine/engine_test.go | 9 ---- factory.go | 7 +++ factory_test.go | 9 ++++ go.mod | 8 +-- go.sum | 12 ++--- engine/interface.go => interface.go | 2 +- 14 files changed, 70 insertions(+), 191 deletions(-) delete mode 100644 engine/engine_test.go create mode 100644 factory.go create mode 100644 factory_test.go rename engine/interface.go => interface.go (99%) diff --git a/engine/engine_balance_redis_test.go b/engine/engine_balance_redis_test.go index 6593198..31193b2 100644 --- a/engine/engine_balance_redis_test.go +++ b/engine/engine_balance_redis_test.go @@ -6,10 +6,8 @@ import ( "strconv" "testing" - "github.com/xh3b4sd/budget/v3/pkg/breaker" "github.com/xh3b4sd/logger" "github.com/xh3b4sd/redigo" - "github.com/xh3b4sd/redigo/pkg/client" "github.com/xh3b4sd/rescue/task" ) @@ -18,18 +16,10 @@ func Test_Engine_Balance(t *testing.T) { var red redigo.Interface { - c := client.Config{ - Kind: client.KindSingle, - Locker: client.ConfigLocker{ - Budget: breaker.Default(), - }, - } - - red, err = client.New(c) - if err != nil { - t.Fatal(err) - } + red = redigo.Default() + } + { err = red.Purge() if err != nil { t.Fatal(err) diff --git a/engine/engine_create_redis_test.go b/engine/engine_create_redis_test.go index 2580eff..c93da25 100644 --- a/engine/engine_create_redis_test.go +++ b/engine/engine_create_redis_test.go @@ -6,10 +6,8 @@ import ( "fmt" "testing" - "github.com/xh3b4sd/budget/v3/pkg/breaker" "github.com/xh3b4sd/logger" "github.com/xh3b4sd/redigo" - "github.com/xh3b4sd/redigo/pkg/client" "github.com/xh3b4sd/rescue/task" ) @@ -18,18 +16,10 @@ func Test_Engine_Create(t *testing.T) { var red redigo.Interface { - c := client.Config{ - Kind: client.KindSingle, - Locker: client.ConfigLocker{ - Budget: breaker.Default(), - }, - } - - red, err = client.New(c) - if err != nil { - t.Fatal(err) - } + red = redigo.Default() + } + { err = red.Purge() if err != nil { t.Fatal(err) @@ -241,18 +231,10 @@ func Test_Engine_Create_Cron(t *testing.T) { var red redigo.Interface { - c := client.Config{ - Kind: client.KindSingle, - Locker: client.ConfigLocker{ - Budget: breaker.Default(), - }, - } - - red, err = client.New(c) - if err != nil { - t.Fatal(err) - } + red = redigo.Default() + } + { err = red.Purge() if err != nil { t.Fatal(err) @@ -439,18 +421,10 @@ func Test_Engine_Create_Root_First(t *testing.T) { var red redigo.Interface { - c := client.Config{ - Kind: client.KindSingle, - Locker: client.ConfigLocker{ - Budget: breaker.Default(), - }, - } - - red, err = client.New(c) - if err != nil { - t.Fatal(err) - } + red = redigo.Default() + } + { err = red.Purge() if err != nil { t.Fatal(err) diff --git a/engine/engine_delete_redis_test.go b/engine/engine_delete_redis_test.go index 9f401c8..65cef8f 100644 --- a/engine/engine_delete_redis_test.go +++ b/engine/engine_delete_redis_test.go @@ -6,10 +6,8 @@ import ( "testing" "time" - "github.com/xh3b4sd/budget/v3/pkg/breaker" "github.com/xh3b4sd/logger" "github.com/xh3b4sd/redigo" - "github.com/xh3b4sd/redigo/pkg/client" "github.com/xh3b4sd/rescue/task" ) @@ -18,18 +16,10 @@ func Test_Engine_Delete(t *testing.T) { var red redigo.Interface { - c := client.Config{ - Kind: client.KindSingle, - Locker: client.ConfigLocker{ - Budget: breaker.Default(), - }, - } - - red, err = client.New(c) - if err != nil { - t.Fatal(err) - } + red = redigo.Default() + } + { err = red.Purge() if err != nil { t.Fatal(err) diff --git a/engine/engine_exists_redis_test.go b/engine/engine_exists_redis_test.go index 5f3f269..31f62ea 100644 --- a/engine/engine_exists_redis_test.go +++ b/engine/engine_exists_redis_test.go @@ -6,10 +6,8 @@ import ( "testing" "time" - "github.com/xh3b4sd/budget/v3/pkg/breaker" "github.com/xh3b4sd/logger" "github.com/xh3b4sd/redigo" - "github.com/xh3b4sd/redigo/pkg/client" "github.com/xh3b4sd/rescue/task" ) @@ -18,18 +16,10 @@ func Test_Engine_Exists(t *testing.T) { var red redigo.Interface { - c := client.Config{ - Kind: client.KindSingle, - Locker: client.ConfigLocker{ - Budget: breaker.Default(), - }, - } - - red, err = client.New(c) - if err != nil { - t.Fatal(err) - } + red = redigo.Default() + } + { err = red.Purge() if err != nil { t.Fatal(err) diff --git a/engine/engine_expire_redis_test.go b/engine/engine_expire_redis_test.go index 253accf..111336d 100644 --- a/engine/engine_expire_redis_test.go +++ b/engine/engine_expire_redis_test.go @@ -6,10 +6,8 @@ import ( "testing" "time" - "github.com/xh3b4sd/budget/v3/pkg/breaker" "github.com/xh3b4sd/logger" "github.com/xh3b4sd/redigo" - "github.com/xh3b4sd/redigo/pkg/client" "github.com/xh3b4sd/rescue/task" ) @@ -18,18 +16,10 @@ func Test_Engine_Expire(t *testing.T) { var red redigo.Interface { - c := client.Config{ - Kind: client.KindSingle, - Locker: client.ConfigLocker{ - Budget: breaker.Default(), - }, - } - - red, err = client.New(c) - if err != nil { - t.Fatal(err) - } + red = redigo.Default() + } + { err = red.Purge() if err != nil { t.Fatal(err) diff --git a/engine/engine_extend_redis_test.go b/engine/engine_extend_redis_test.go index 5f1711c..76ab29e 100644 --- a/engine/engine_extend_redis_test.go +++ b/engine/engine_extend_redis_test.go @@ -6,10 +6,8 @@ import ( "testing" "time" - "github.com/xh3b4sd/budget/v3/pkg/breaker" "github.com/xh3b4sd/logger" "github.com/xh3b4sd/redigo" - "github.com/xh3b4sd/redigo/pkg/client" "github.com/xh3b4sd/rescue/task" ) @@ -18,18 +16,10 @@ func Test_Engine_Extend(t *testing.T) { var red redigo.Interface { - c := client.Config{ - Kind: client.KindSingle, - Locker: client.ConfigLocker{ - Budget: breaker.Default(), - }, - } - - red, err = client.New(c) - if err != nil { - t.Fatal(err) - } + red = redigo.Default() + } + { err = red.Purge() if err != nil { t.Fatal(err) diff --git a/engine/engine_lifecycle_redis_test.go b/engine/engine_lifecycle_redis_test.go index de0cab1..9372e3e 100644 --- a/engine/engine_lifecycle_redis_test.go +++ b/engine/engine_lifecycle_redis_test.go @@ -8,10 +8,8 @@ import ( "testing" "time" - "github.com/xh3b4sd/budget/v3/pkg/breaker" "github.com/xh3b4sd/logger" "github.com/xh3b4sd/redigo" - "github.com/xh3b4sd/redigo/pkg/client" "github.com/xh3b4sd/rescue/task" "github.com/xh3b4sd/rescue/timer" "github.com/xh3b4sd/tracer" @@ -22,21 +20,13 @@ func Test_Engine_Lifecycle_Cron_Weekday(t *testing.T) { var red redigo.Interface { - c := client.Config{ - Kind: client.KindSingle, - Locker: client.ConfigLocker{ - Budget: breaker.Default(), - }, - } - - red, err = client.New(c) - if err != nil { - t.Fatal("expected", true, "got", false) - } + red = redigo.Default() + } + { err = red.Purge() if err != nil { - t.Fatal("expected", true, "got", false) + t.Fatal(err) } } @@ -203,18 +193,10 @@ func Test_Engine_Lifecycle_Cron_Failure(t *testing.T) { var red redigo.Interface { - c := client.Config{ - Kind: client.KindSingle, - Locker: client.ConfigLocker{ - Budget: breaker.Default(), - }, - } - - red, err = client.New(c) - if err != nil { - t.Fatal(err) - } + red = redigo.Default() + } + { err = red.Purge() if err != nil { t.Fatal(err) @@ -732,18 +714,10 @@ func Test_Engine_Lifecycle_Cron_Resolve(t *testing.T) { var red redigo.Interface { - c := client.Config{ - Kind: client.KindSingle, - Locker: client.ConfigLocker{ - Budget: breaker.Default(), - }, - } - - red, err = client.New(c) - if err != nil { - t.Fatal(err) - } + red = redigo.Default() + } + { err = red.Purge() if err != nil { t.Fatal(err) @@ -1156,18 +1130,10 @@ func Test_Engine_Lifecycle_Race(t *testing.T) { var red redigo.Interface { - c := client.Config{ - Kind: client.KindSingle, - Locker: client.ConfigLocker{ - Budget: breaker.Default(), - }, - } - - red, err = client.New(c) - if err != nil { - t.Fatal(err) - } + red = redigo.Default() + } + { err = red.Purge() if err != nil { t.Fatal(err) @@ -1377,18 +1343,10 @@ func Test_Engine_Lifecycle_Sync(t *testing.T) { var red redigo.Interface { - c := client.Config{ - Kind: client.KindSingle, - Locker: client.ConfigLocker{ - Budget: breaker.Default(), - }, - } - - red, err = client.New(c) - if err != nil { - t.Fatal(err) - } + red = redigo.Default() + } + { err = red.Purge() if err != nil { t.Fatal(err) diff --git a/engine/engine_lister_redis_test.go b/engine/engine_lister_redis_test.go index 4da886b..923f8f1 100644 --- a/engine/engine_lister_redis_test.go +++ b/engine/engine_lister_redis_test.go @@ -6,10 +6,8 @@ import ( "testing" "time" - "github.com/xh3b4sd/budget/v3/pkg/breaker" "github.com/xh3b4sd/logger" "github.com/xh3b4sd/redigo" - "github.com/xh3b4sd/redigo/pkg/client" "github.com/xh3b4sd/rescue/task" ) @@ -18,18 +16,10 @@ func Test_Engine_Lister(t *testing.T) { var red redigo.Interface { - c := client.Config{ - Kind: client.KindSingle, - Locker: client.ConfigLocker{ - Budget: breaker.Default(), - }, - } - - red, err = client.New(c) - if err != nil { - t.Fatal(err) - } + red = redigo.Default() + } + { err = red.Purge() if err != nil { t.Fatal(err) diff --git a/engine/engine_test.go b/engine/engine_test.go deleted file mode 100644 index 44ad056..0000000 --- a/engine/engine_test.go +++ /dev/null @@ -1,9 +0,0 @@ -package engine - -import ( - "testing" -) - -func Test_Engine_Interface(t *testing.T) { - var _ Interface = New(Config{}) -} diff --git a/factory.go b/factory.go new file mode 100644 index 0000000..cb1a313 --- /dev/null +++ b/factory.go @@ -0,0 +1,7 @@ +package rescue + +import "github.com/xh3b4sd/rescue/engine" + +func Default() Interface { + return engine.New(engine.Config{}) +} diff --git a/factory_test.go b/factory_test.go new file mode 100644 index 0000000..0993975 --- /dev/null +++ b/factory_test.go @@ -0,0 +1,9 @@ +package rescue + +import ( + "testing" +) + +func Test_Factory_Interface_Default(t *testing.T) { + var _ Interface = Default() +} diff --git a/go.mod b/go.mod index 7fb0af7..0983b8b 100644 --- a/go.mod +++ b/go.mod @@ -6,9 +6,8 @@ require ( github.com/google/go-cmp v0.6.0 github.com/google/uuid v1.3.1 github.com/prometheus/client_golang v1.17.0 - github.com/xh3b4sd/budget/v3 v3.3.0 github.com/xh3b4sd/logger v0.7.3 - github.com/xh3b4sd/redigo v0.35.1 + github.com/xh3b4sd/redigo v0.36.0 github.com/xh3b4sd/tracer v0.10.1 ) @@ -22,10 +21,11 @@ require ( github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect - github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect + github.com/prometheus/client_model v0.5.0 // indirect github.com/prometheus/common v0.44.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect - golang.org/x/sys v0.12.0 // indirect + github.com/xh3b4sd/budget/v3 v3.3.0 // indirect + golang.org/x/sys v0.13.0 // indirect google.golang.org/protobuf v1.31.0 // indirect ) diff --git a/go.sum b/go.sum index f736f52..27209a1 100644 --- a/go.sum +++ b/go.sum @@ -103,8 +103,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q= github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY= -github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 h1:v7DLqVdK4VrYkVD5diGdl4sxJurKJEMnODWRJlxV9oM= -github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU= +github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= +github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY= github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY= github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= @@ -130,8 +130,8 @@ github.com/xh3b4sd/budget/v3 v3.3.0 h1:/mg11kyDuYHI4LOT8hctLsVnK6ZeGN+/Rw5wzZ/Zh github.com/xh3b4sd/budget/v3 v3.3.0/go.mod h1:epHdjvXVpg5PE63RcBirhgY8D/vVa5dbXkDjQ/ycT40= github.com/xh3b4sd/logger v0.7.3 h1:iqzUqU3sd8cn5RZda/0GWGdJRA9j9qCBDYZBda7ti70= github.com/xh3b4sd/logger v0.7.3/go.mod h1:fIvpHlYAJFR/xbWtyuVlnZKyWhGI78C2RUbWDEBhT4k= -github.com/xh3b4sd/redigo v0.35.1 h1:BWEyzsq+OEpgPinTuLeKlHn6epWM16hDyPLeTjAFlKA= -github.com/xh3b4sd/redigo v0.35.1/go.mod h1:FezZ2igUyrLcJvR6RLvD/YpGL1GCbVY6bGQfJ6S4pYk= +github.com/xh3b4sd/redigo v0.36.0 h1:xbhl5v+h9B+5HpqJ49YkuRzjEcoQk9KagUW2bjff+1E= +github.com/xh3b4sd/redigo v0.36.0/go.mod h1:FezZ2igUyrLcJvR6RLvD/YpGL1GCbVY6bGQfJ6S4pYk= github.com/xh3b4sd/tracer v0.10.1 h1:wuzVeQtqYsy51Nkb7P/XavZ8rQYptxxmlM1ivFJ8dXE= github.com/xh3b4sd/tracer v0.10.1/go.mod h1:8nRbNXXhSSDmPfyoRRYgwQt/RpzAUH+zNsagP9InH8M= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -210,8 +210,8 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= diff --git a/engine/interface.go b/interface.go similarity index 99% rename from engine/interface.go rename to interface.go index 1b2f1d1..dc05312 100644 --- a/engine/interface.go +++ b/interface.go @@ -1,4 +1,4 @@ -package engine +package rescue import ( "github.com/xh3b4sd/rescue/task"