diff --git a/pkg/agent/sidecar/service/observer/observer_test.go b/pkg/agent/sidecar/service/observer/observer_test.go index f921af0387f..e1f441a3fa3 100644 --- a/pkg/agent/sidecar/service/observer/observer_test.go +++ b/pkg/agent/sidecar/service/observer/observer_test.go @@ -85,7 +85,7 @@ func TestNew(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -110,12 +110,16 @@ func Test_observer_Start(t *testing.T) { ctx context.Context } type fields struct { - w watch.Watcher - dir string - eg errgroup.Group - checkDuration time.Duration - storage storage.Storage - ch chan struct{} + w watch.Watcher + dir string + eg errgroup.Group + checkDuration time.Duration + metadataPath string + postStopTimeout time.Duration + watchEnabled bool + tickerEnabled bool + storage storage.Storage + ch chan struct{} } type want struct { want <-chan error @@ -152,6 +156,10 @@ func Test_observer_Start(t *testing.T) { dir: "", eg: nil, checkDuration: nil, + metadataPath: "", + postStopTimeout: nil, + watchEnabled: false, + tickerEnabled: false, storage: nil, ch: nil, }, @@ -173,6 +181,10 @@ func Test_observer_Start(t *testing.T) { dir: "", eg: nil, checkDuration: nil, + metadataPath: "", + postStopTimeout: nil, + watchEnabled: false, + tickerEnabled: false, storage: nil, ch: nil, }, @@ -185,7 +197,7 @@ func Test_observer_Start(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -196,12 +208,16 @@ func Test_observer_Start(t *testing.T) { test.checkFunc = defaultCheckFunc } o := &observer{ - w: test.fields.w, - dir: test.fields.dir, - eg: test.fields.eg, - checkDuration: test.fields.checkDuration, - storage: test.fields.storage, - ch: test.fields.ch, + w: test.fields.w, + dir: test.fields.dir, + eg: test.fields.eg, + checkDuration: test.fields.checkDuration, + metadataPath: test.fields.metadataPath, + postStopTimeout: test.fields.postStopTimeout, + watchEnabled: test.fields.watchEnabled, + tickerEnabled: test.fields.tickerEnabled, + storage: test.fields.storage, + ch: test.fields.ch, } got, err := o.Start(test.args.ctx) @@ -213,17 +229,141 @@ func Test_observer_Start(t *testing.T) { } } +func Test_observer_PostStop(t *testing.T) { + type args struct { + ctx context.Context + } + type fields struct { + w watch.Watcher + dir string + eg errgroup.Group + checkDuration time.Duration + metadataPath string + postStopTimeout time.Duration + watchEnabled bool + tickerEnabled bool + storage storage.Storage + ch chan struct{} + } + type want struct { + err error + } + type test struct { + name string + args args + fields fields + want want + checkFunc func(want, error) error + beforeFunc func(args) + afterFunc func(args) + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + ctx: nil, + }, + fields: fields { + w: nil, + dir: "", + eg: nil, + checkDuration: nil, + metadataPath: "", + postStopTimeout: nil, + watchEnabled: false, + tickerEnabled: false, + storage: nil, + ch: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + ctx: nil, + }, + fields: fields { + w: nil, + dir: "", + eg: nil, + checkDuration: nil, + metadataPath: "", + postStopTimeout: nil, + watchEnabled: false, + tickerEnabled: false, + storage: nil, + ch: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + } + }(), + */ + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + defer goleak.VerifyNone(tt) + if test.beforeFunc != nil { + test.beforeFunc(test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(test.args) + } + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + o := &observer{ + w: test.fields.w, + dir: test.fields.dir, + eg: test.fields.eg, + checkDuration: test.fields.checkDuration, + metadataPath: test.fields.metadataPath, + postStopTimeout: test.fields.postStopTimeout, + watchEnabled: test.fields.watchEnabled, + tickerEnabled: test.fields.tickerEnabled, + storage: test.fields.storage, + ch: test.fields.ch, + } + + err := o.PostStop(test.args.ctx) + if err := test.checkFunc(test.want, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + func Test_observer_startTicker(t *testing.T) { type args struct { ctx context.Context } type fields struct { - w watch.Watcher - dir string - eg errgroup.Group - checkDuration time.Duration - storage storage.Storage - ch chan struct{} + w watch.Watcher + dir string + eg errgroup.Group + checkDuration time.Duration + metadataPath string + postStopTimeout time.Duration + watchEnabled bool + tickerEnabled bool + storage storage.Storage + ch chan struct{} } type want struct { want <-chan error @@ -260,6 +400,10 @@ func Test_observer_startTicker(t *testing.T) { dir: "", eg: nil, checkDuration: nil, + metadataPath: "", + postStopTimeout: nil, + watchEnabled: false, + tickerEnabled: false, storage: nil, ch: nil, }, @@ -281,6 +425,10 @@ func Test_observer_startTicker(t *testing.T) { dir: "", eg: nil, checkDuration: nil, + metadataPath: "", + postStopTimeout: nil, + watchEnabled: false, + tickerEnabled: false, storage: nil, ch: nil, }, @@ -293,7 +441,7 @@ func Test_observer_startTicker(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -304,12 +452,16 @@ func Test_observer_startTicker(t *testing.T) { test.checkFunc = defaultCheckFunc } o := &observer{ - w: test.fields.w, - dir: test.fields.dir, - eg: test.fields.eg, - checkDuration: test.fields.checkDuration, - storage: test.fields.storage, - ch: test.fields.ch, + w: test.fields.w, + dir: test.fields.dir, + eg: test.fields.eg, + checkDuration: test.fields.checkDuration, + metadataPath: test.fields.metadataPath, + postStopTimeout: test.fields.postStopTimeout, + watchEnabled: test.fields.watchEnabled, + tickerEnabled: test.fields.tickerEnabled, + storage: test.fields.storage, + ch: test.fields.ch, } got, err := o.startTicker(test.args.ctx) @@ -326,12 +478,16 @@ func Test_observer_startBackupLoop(t *testing.T) { ctx context.Context } type fields struct { - w watch.Watcher - dir string - eg errgroup.Group - checkDuration time.Duration - storage storage.Storage - ch chan struct{} + w watch.Watcher + dir string + eg errgroup.Group + checkDuration time.Duration + metadataPath string + postStopTimeout time.Duration + watchEnabled bool + tickerEnabled bool + storage storage.Storage + ch chan struct{} } type want struct { want <-chan error @@ -368,6 +524,10 @@ func Test_observer_startBackupLoop(t *testing.T) { dir: "", eg: nil, checkDuration: nil, + metadataPath: "", + postStopTimeout: nil, + watchEnabled: false, + tickerEnabled: false, storage: nil, ch: nil, }, @@ -389,6 +549,10 @@ func Test_observer_startBackupLoop(t *testing.T) { dir: "", eg: nil, checkDuration: nil, + metadataPath: "", + postStopTimeout: nil, + watchEnabled: false, + tickerEnabled: false, storage: nil, ch: nil, }, @@ -401,7 +565,7 @@ func Test_observer_startBackupLoop(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -412,12 +576,16 @@ func Test_observer_startBackupLoop(t *testing.T) { test.checkFunc = defaultCheckFunc } o := &observer{ - w: test.fields.w, - dir: test.fields.dir, - eg: test.fields.eg, - checkDuration: test.fields.checkDuration, - storage: test.fields.storage, - ch: test.fields.ch, + w: test.fields.w, + dir: test.fields.dir, + eg: test.fields.eg, + checkDuration: test.fields.checkDuration, + metadataPath: test.fields.metadataPath, + postStopTimeout: test.fields.postStopTimeout, + watchEnabled: test.fields.watchEnabled, + tickerEnabled: test.fields.tickerEnabled, + storage: test.fields.storage, + ch: test.fields.ch, } got, err := o.startBackupLoop(test.args.ctx) @@ -435,12 +603,16 @@ func Test_observer_onWrite(t *testing.T) { name string } type fields struct { - w watch.Watcher - dir string - eg errgroup.Group - checkDuration time.Duration - storage storage.Storage - ch chan struct{} + w watch.Watcher + dir string + eg errgroup.Group + checkDuration time.Duration + metadataPath string + postStopTimeout time.Duration + watchEnabled bool + tickerEnabled bool + storage storage.Storage + ch chan struct{} } type want struct { err error @@ -474,6 +646,10 @@ func Test_observer_onWrite(t *testing.T) { dir: "", eg: nil, checkDuration: nil, + metadataPath: "", + postStopTimeout: nil, + watchEnabled: false, + tickerEnabled: false, storage: nil, ch: nil, }, @@ -496,6 +672,10 @@ func Test_observer_onWrite(t *testing.T) { dir: "", eg: nil, checkDuration: nil, + metadataPath: "", + postStopTimeout: nil, + watchEnabled: false, + tickerEnabled: false, storage: nil, ch: nil, }, @@ -508,7 +688,7 @@ func Test_observer_onWrite(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -519,12 +699,16 @@ func Test_observer_onWrite(t *testing.T) { test.checkFunc = defaultCheckFunc } o := &observer{ - w: test.fields.w, - dir: test.fields.dir, - eg: test.fields.eg, - checkDuration: test.fields.checkDuration, - storage: test.fields.storage, - ch: test.fields.ch, + w: test.fields.w, + dir: test.fields.dir, + eg: test.fields.eg, + checkDuration: test.fields.checkDuration, + metadataPath: test.fields.metadataPath, + postStopTimeout: test.fields.postStopTimeout, + watchEnabled: test.fields.watchEnabled, + tickerEnabled: test.fields.tickerEnabled, + storage: test.fields.storage, + ch: test.fields.ch, } err := o.onWrite(test.args.ctx, test.args.name) @@ -542,12 +726,16 @@ func Test_observer_onCreate(t *testing.T) { name string } type fields struct { - w watch.Watcher - dir string - eg errgroup.Group - checkDuration time.Duration - storage storage.Storage - ch chan struct{} + w watch.Watcher + dir string + eg errgroup.Group + checkDuration time.Duration + metadataPath string + postStopTimeout time.Duration + watchEnabled bool + tickerEnabled bool + storage storage.Storage + ch chan struct{} } type want struct { err error @@ -581,6 +769,10 @@ func Test_observer_onCreate(t *testing.T) { dir: "", eg: nil, checkDuration: nil, + metadataPath: "", + postStopTimeout: nil, + watchEnabled: false, + tickerEnabled: false, storage: nil, ch: nil, }, @@ -603,6 +795,10 @@ func Test_observer_onCreate(t *testing.T) { dir: "", eg: nil, checkDuration: nil, + metadataPath: "", + postStopTimeout: nil, + watchEnabled: false, + tickerEnabled: false, storage: nil, ch: nil, }, @@ -615,7 +811,7 @@ func Test_observer_onCreate(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -626,12 +822,16 @@ func Test_observer_onCreate(t *testing.T) { test.checkFunc = defaultCheckFunc } o := &observer{ - w: test.fields.w, - dir: test.fields.dir, - eg: test.fields.eg, - checkDuration: test.fields.checkDuration, - storage: test.fields.storage, - ch: test.fields.ch, + w: test.fields.w, + dir: test.fields.dir, + eg: test.fields.eg, + checkDuration: test.fields.checkDuration, + metadataPath: test.fields.metadataPath, + postStopTimeout: test.fields.postStopTimeout, + watchEnabled: test.fields.watchEnabled, + tickerEnabled: test.fields.tickerEnabled, + storage: test.fields.storage, + ch: test.fields.ch, } err := o.onCreate(test.args.ctx, test.args.name) @@ -643,34 +843,42 @@ func Test_observer_onCreate(t *testing.T) { } } -func Test_observer_requestBackup(t *testing.T) { +func Test_observer_checkCondition(t *testing.T) { type args struct { - ctx context.Context + name string } type fields struct { - w watch.Watcher - dir string - eg errgroup.Group - checkDuration time.Duration - storage storage.Storage - ch chan struct{} + w watch.Watcher + dir string + eg errgroup.Group + checkDuration time.Duration + metadataPath string + postStopTimeout time.Duration + watchEnabled bool + tickerEnabled bool + storage storage.Storage + ch chan struct{} } type want struct { - err error + want bool + err error } type test struct { name string args args fields fields want want - checkFunc func(want, error) error + checkFunc func(want, bool, error) error beforeFunc func(args) afterFunc func(args) } - defaultCheckFunc := func(w want, err error) error { + defaultCheckFunc := func(w want, got bool, err error) error { if !errors.Is(err, w.err) { return errors.Errorf("got error = %v, want %v", err, w.err) } + if !reflect.DeepEqual(got, w.want) { + return errors.Errorf("got = %v, want %v", got, w.want) + } return nil } tests := []test{ @@ -679,13 +887,17 @@ func Test_observer_requestBackup(t *testing.T) { { name: "test_case_1", args: args { - ctx: nil, + name: "", }, fields: fields { w: nil, dir: "", eg: nil, checkDuration: nil, + metadataPath: "", + postStopTimeout: nil, + watchEnabled: false, + tickerEnabled: false, storage: nil, ch: nil, }, @@ -700,13 +912,17 @@ func Test_observer_requestBackup(t *testing.T) { return test { name: "test_case_2", args: args { - ctx: nil, + name: "", }, fields: fields { w: nil, dir: "", eg: nil, checkDuration: nil, + metadataPath: "", + postStopTimeout: nil, + watchEnabled: false, + tickerEnabled: false, storage: nil, ch: nil, }, @@ -719,7 +935,7 @@ func Test_observer_requestBackup(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -730,15 +946,129 @@ func Test_observer_requestBackup(t *testing.T) { test.checkFunc = defaultCheckFunc } o := &observer{ - w: test.fields.w, - dir: test.fields.dir, - eg: test.fields.eg, - checkDuration: test.fields.checkDuration, - storage: test.fields.storage, - ch: test.fields.ch, + w: test.fields.w, + dir: test.fields.dir, + eg: test.fields.eg, + checkDuration: test.fields.checkDuration, + metadataPath: test.fields.metadataPath, + postStopTimeout: test.fields.postStopTimeout, + watchEnabled: test.fields.watchEnabled, + tickerEnabled: test.fields.tickerEnabled, + storage: test.fields.storage, + ch: test.fields.ch, } - err := o.requestBackup(test.args.ctx) + got, err := o.checkCondition(test.args.name) + if err := test.checkFunc(test.want, got, err); err != nil { + tt.Errorf("error = %v", err) + } + + }) + } +} + +func Test_observer_terminate(t *testing.T) { + type fields struct { + w watch.Watcher + dir string + eg errgroup.Group + checkDuration time.Duration + metadataPath string + postStopTimeout time.Duration + watchEnabled bool + tickerEnabled bool + storage storage.Storage + ch chan struct{} + } + type want struct { + err error + } + type test struct { + name string + fields fields + want want + checkFunc func(want, error) error + beforeFunc func() + afterFunc func() + } + defaultCheckFunc := func(w want, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + return nil + } + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + fields: fields { + w: nil, + dir: "", + eg: nil, + checkDuration: nil, + metadataPath: "", + postStopTimeout: nil, + watchEnabled: false, + tickerEnabled: false, + storage: nil, + ch: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + fields: fields { + w: nil, + dir: "", + eg: nil, + checkDuration: nil, + metadataPath: "", + postStopTimeout: nil, + watchEnabled: false, + tickerEnabled: false, + storage: nil, + ch: nil, + }, + want: want{}, + checkFunc: defaultCheckFunc, + } + }(), + */ + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + defer goleak.VerifyNone(tt) + if test.beforeFunc != nil { + test.beforeFunc() + } + if test.afterFunc != nil { + defer test.afterFunc() + } + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + o := &observer{ + w: test.fields.w, + dir: test.fields.dir, + eg: test.fields.eg, + checkDuration: test.fields.checkDuration, + metadataPath: test.fields.metadataPath, + postStopTimeout: test.fields.postStopTimeout, + watchEnabled: test.fields.watchEnabled, + tickerEnabled: test.fields.tickerEnabled, + storage: test.fields.storage, + ch: test.fields.ch, + } + + err := o.terminate() if err := test.checkFunc(test.want, err); err != nil { tt.Errorf("error = %v", err) } @@ -747,17 +1077,21 @@ func Test_observer_requestBackup(t *testing.T) { } } -func Test_observer_backup(t *testing.T) { +func Test_observer_requestBackup(t *testing.T) { type args struct { ctx context.Context } type fields struct { - w watch.Watcher - dir string - eg errgroup.Group - checkDuration time.Duration - storage storage.Storage - ch chan struct{} + w watch.Watcher + dir string + eg errgroup.Group + checkDuration time.Duration + metadataPath string + postStopTimeout time.Duration + watchEnabled bool + tickerEnabled bool + storage storage.Storage + ch chan struct{} } type want struct { err error @@ -790,6 +1124,10 @@ func Test_observer_backup(t *testing.T) { dir: "", eg: nil, checkDuration: nil, + metadataPath: "", + postStopTimeout: nil, + watchEnabled: false, + tickerEnabled: false, storage: nil, ch: nil, }, @@ -811,6 +1149,10 @@ func Test_observer_backup(t *testing.T) { dir: "", eg: nil, checkDuration: nil, + metadataPath: "", + postStopTimeout: nil, + watchEnabled: false, + tickerEnabled: false, storage: nil, ch: nil, }, @@ -823,7 +1165,7 @@ func Test_observer_backup(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -834,15 +1176,19 @@ func Test_observer_backup(t *testing.T) { test.checkFunc = defaultCheckFunc } o := &observer{ - w: test.fields.w, - dir: test.fields.dir, - eg: test.fields.eg, - checkDuration: test.fields.checkDuration, - storage: test.fields.storage, - ch: test.fields.ch, + w: test.fields.w, + dir: test.fields.dir, + eg: test.fields.eg, + checkDuration: test.fields.checkDuration, + metadataPath: test.fields.metadataPath, + postStopTimeout: test.fields.postStopTimeout, + watchEnabled: test.fields.watchEnabled, + tickerEnabled: test.fields.tickerEnabled, + storage: test.fields.storage, + ch: test.fields.ch, } - err := o.backup(test.args.ctx) + err := o.requestBackup(test.args.ctx) if err := test.checkFunc(test.want, err); err != nil { tt.Errorf("error = %v", err) } @@ -851,7 +1197,7 @@ func Test_observer_backup(t *testing.T) { } } -func Test_observer_PostStop(t *testing.T) { +func Test_observer_backup(t *testing.T) { type args struct { ctx context.Context } @@ -860,7 +1206,10 @@ func Test_observer_PostStop(t *testing.T) { dir string eg errgroup.Group checkDuration time.Duration + metadataPath string postStopTimeout time.Duration + watchEnabled bool + tickerEnabled bool storage storage.Storage ch chan struct{} } @@ -895,7 +1244,10 @@ func Test_observer_PostStop(t *testing.T) { dir: "", eg: nil, checkDuration: nil, + metadataPath: "", postStopTimeout: nil, + watchEnabled: false, + tickerEnabled: false, storage: nil, ch: nil, }, @@ -917,7 +1269,10 @@ func Test_observer_PostStop(t *testing.T) { dir: "", eg: nil, checkDuration: nil, + metadataPath: "", postStopTimeout: nil, + watchEnabled: false, + tickerEnabled: false, storage: nil, ch: nil, }, @@ -930,7 +1285,7 @@ func Test_observer_PostStop(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -945,12 +1300,15 @@ func Test_observer_PostStop(t *testing.T) { dir: test.fields.dir, eg: test.fields.eg, checkDuration: test.fields.checkDuration, + metadataPath: test.fields.metadataPath, postStopTimeout: test.fields.postStopTimeout, + watchEnabled: test.fields.watchEnabled, + tickerEnabled: test.fields.tickerEnabled, storage: test.fields.storage, ch: test.fields.ch, } - err := o.PostStop(test.args.ctx) + err := o.backup(test.args.ctx) if err := test.checkFunc(test.want, err); err != nil { tt.Errorf("error = %v", err) } diff --git a/pkg/agent/sidecar/service/observer/option_test.go b/pkg/agent/sidecar/service/observer/option_test.go index a75bce7e763..6bebf5c0161 100644 --- a/pkg/agent/sidecar/service/observer/option_test.go +++ b/pkg/agent/sidecar/service/observer/option_test.go @@ -26,6 +26,7 @@ import ( ) func TestWithBackupDuration(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { dur string @@ -63,7 +64,7 @@ func TestWithBackupDuration(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -101,7 +102,7 @@ func TestWithBackupDuration(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -122,7 +123,7 @@ func TestWithBackupDuration(t *testing.T) { } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc @@ -130,7 +131,7 @@ func TestWithBackupDuration(t *testing.T) { got := WithBackupDuration(test.args.dur) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -138,7 +139,8 @@ func TestWithBackupDuration(t *testing.T) { } } -func TestWithBackupDurationLimit(t *testing.T) { +func TestWithPostStopTimeout(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { dur string @@ -176,7 +178,7 @@ func TestWithBackupDurationLimit(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -214,7 +216,7 @@ func TestWithBackupDurationLimit(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -228,22 +230,22 @@ func TestWithBackupDurationLimit(t *testing.T) { test.checkFunc = defaultCheckFunc } - got := WithBackupDurationLimit(test.args.dur) + got := WithPostStopTimeout(test.args.dur) obj := new(T) if err := test.checkFunc(test.want, obj, got(obj)); err != nil { tt.Errorf("error = %v", err) } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc } - got := WithBackupDurationLimit(test.args.dur) + got := WithPostStopTimeout(test.args.dur) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -251,10 +253,11 @@ func TestWithBackupDurationLimit(t *testing.T) { } } -func TestWithErrGroup(t *testing.T) { +func TestWithWatch(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { - eg errgroup.Group + enabled bool } type want struct { obj *T @@ -289,7 +292,7 @@ func TestWithErrGroup(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -301,7 +304,7 @@ func TestWithErrGroup(t *testing.T) { { name: "test_case_1", args: args { - eg: nil, + enabled: false, }, want: want { obj: new(T), @@ -315,7 +318,7 @@ func TestWithErrGroup(t *testing.T) { return test { name: "test_case_2", args: args { - eg: nil, + enabled: false, }, want: want { obj: new(T), @@ -327,7 +330,7 @@ func TestWithErrGroup(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -341,22 +344,22 @@ func TestWithErrGroup(t *testing.T) { test.checkFunc = defaultCheckFunc } - got := WithErrGroup(test.args.eg) + got := WithWatch(test.args.enabled) obj := new(T) if err := test.checkFunc(test.want, obj, got(obj)); err != nil { tt.Errorf("error = %v", err) } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc } - got := WithErrGroup(test.args.eg) + got := WithWatch(test.args.enabled) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -364,10 +367,11 @@ func TestWithErrGroup(t *testing.T) { } } -func TestWithDir(t *testing.T) { +func TestWithTicker(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { - dir string + enabled bool } type want struct { obj *T @@ -402,7 +406,7 @@ func TestWithDir(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -414,7 +418,7 @@ func TestWithDir(t *testing.T) { { name: "test_case_1", args: args { - dir: "", + enabled: false, }, want: want { obj: new(T), @@ -428,7 +432,7 @@ func TestWithDir(t *testing.T) { return test { name: "test_case_2", args: args { - dir: "", + enabled: false, }, want: want { obj: new(T), @@ -440,7 +444,7 @@ func TestWithDir(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -454,22 +458,22 @@ func TestWithDir(t *testing.T) { test.checkFunc = defaultCheckFunc } - got := WithDir(test.args.dir) + got := WithTicker(test.args.enabled) obj := new(T) if err := test.checkFunc(test.want, obj, got(obj)); err != nil { tt.Errorf("error = %v", err) } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc } - got := WithDir(test.args.dir) + got := WithTicker(test.args.enabled) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -477,10 +481,11 @@ func TestWithDir(t *testing.T) { } } -func TestWithBlobStorage(t *testing.T) { +func TestWithErrGroup(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { - storage storage.Storage + eg errgroup.Group } type want struct { obj *T @@ -515,7 +520,7 @@ func TestWithBlobStorage(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -527,7 +532,7 @@ func TestWithBlobStorage(t *testing.T) { { name: "test_case_1", args: args { - storage: nil, + eg: nil, }, want: want { obj: new(T), @@ -541,7 +546,7 @@ func TestWithBlobStorage(t *testing.T) { return test { name: "test_case_2", args: args { - storage: nil, + eg: nil, }, want: want { obj: new(T), @@ -553,7 +558,7 @@ func TestWithBlobStorage(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -567,22 +572,22 @@ func TestWithBlobStorage(t *testing.T) { test.checkFunc = defaultCheckFunc } - got := WithBlobStorage(test.args.storage) + got := WithErrGroup(test.args.eg) obj := new(T) if err := test.checkFunc(test.want, obj, got(obj)); err != nil { tt.Errorf("error = %v", err) } */ - // Uncomment this block if the option returns an error, otherwise delete it + // Uncomment this block if the option do not return an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc } - got := WithBlobStorage(test.args.storage) + got := WithErrGroup(test.args.eg) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */ @@ -590,10 +595,11 @@ func TestWithBlobStorage(t *testing.T) { } } -func TestWithPostStopTimeout(t *testing.T) { +func TestWithDir(t *testing.T) { + // Change interface type to the type of object you are testing type T = interface{} type args struct { - dur string + dir string } type want struct { obj *T @@ -628,7 +634,7 @@ func TestWithPostStopTimeout(t *testing.T) { /* defaultCheckFunc := func(w want, obj *T) error { if !reflect.DeepEqual(obj, w.obj) { - return errors.Errorf("got = %v, want %v", obj, w.c) + return errors.Errorf("got = %v, want %v", obj, w.obj) } return nil } @@ -640,7 +646,7 @@ func TestWithPostStopTimeout(t *testing.T) { { name: "test_case_1", args: args { - dur: "", + dir: "", }, want: want { obj: new(T), @@ -654,7 +660,7 @@ func TestWithPostStopTimeout(t *testing.T) { return test { name: "test_case_2", args: args { - dur: "", + dir: "", }, want: want { obj: new(T), @@ -666,7 +672,7 @@ func TestWithPostStopTimeout(t *testing.T) { for _, test := range tests { t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) + defer goleak.VerifyNone(tt) if test.beforeFunc != nil { test.beforeFunc(test.args) } @@ -680,22 +686,136 @@ func TestWithPostStopTimeout(t *testing.T) { test.checkFunc = defaultCheckFunc } - got := WithPostStopTimeout(test.args.dur) + got := WithDir(test.args.dir) obj := new(T) if err := test.checkFunc(test.want, obj, got(obj)); err != nil { tt.Errorf("error = %v", err) } */ + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithDir(test.args.dir) + obj := new(T) + got(obj) + if err := test.checkFunc(test.want, obj); err != nil { + tt.Errorf("error = %v", err) + } + */ + }) + } +} + +func TestWithBlobStorage(t *testing.T) { + // Change interface type to the type of object you are testing + type T = interface{} + type args struct { + storage storage.Storage + } + type want struct { + obj *T + // Uncomment this line if the option returns an error, otherwise delete it + // err error + } + type test struct { + name string + args args + want want + // Use the first line if the option returns an error. otherwise use the second line + // checkFunc func(want, *T, error) error + // checkFunc func(want, *T) error + beforeFunc func(args) + afterFunc func(args) + } + + // Uncomment this block if the option returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T, err error) error { + if !errors.Is(err, w.err) { + return errors.Errorf("got error = %v, want %v", err, w.err) + } + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + // Uncomment this block if the option do not returns an error, otherwise delete it + /* + defaultCheckFunc := func(w want, obj *T) error { + if !reflect.DeepEqual(obj, w.obj) { + return errors.Errorf("got = %v, want %v", obj, w.obj) + } + return nil + } + */ + + tests := []test{ + // TODO test cases + /* + { + name: "test_case_1", + args: args { + storage: nil, + }, + want: want { + obj: new(T), + }, + }, + */ + + // TODO test cases + /* + func() test { + return test { + name: "test_case_2", + args: args { + storage: nil, + }, + want: want { + obj: new(T), + }, + } + }(), + */ + } + + for _, test := range tests { + t.Run(test.name, func(tt *testing.T) { + defer goleak.VerifyNone(tt) + if test.beforeFunc != nil { + test.beforeFunc(test.args) + } + if test.afterFunc != nil { + defer test.afterFunc(test.args) + } + // Uncomment this block if the option returns an error, otherwise delete it /* if test.checkFunc == nil { test.checkFunc = defaultCheckFunc } - got := WithPostStopTimeout(test.args.dur) + + got := WithBlobStorage(test.args.storage) + obj := new(T) + if err := test.checkFunc(test.want, obj, got(obj)); err != nil { + tt.Errorf("error = %v", err) + } + */ + + // Uncomment this block if the option do not return an error, otherwise delete it + /* + if test.checkFunc == nil { + test.checkFunc = defaultCheckFunc + } + got := WithBlobStorage(test.args.storage) obj := new(T) got(obj) - if err := test.checkFunc(tt.want, obj); err != nil { + if err := test.checkFunc(test.want, obj); err != nil { tt.Errorf("error = %v", err) } */