diff --git a/internal/config/sidecar.go b/internal/config/sidecar.go index aaf5a7cf0b2..96519a6ddd1 100644 --- a/internal/config/sidecar.go +++ b/internal/config/sidecar.go @@ -17,7 +17,7 @@ // Package config providers configuration type and load configuration logic package config -type Sidecar struct { +type AgentSidecar struct { // Name string `yaml:"name" json:"name"` // WatchPaths represents watch path list for backup @@ -30,7 +30,7 @@ type Sidecar struct { AutoBackupDuration string `yaml:"auto_backup_duration" json:"auto_backup_duration"` } -func (s *Sidecar) Bind() *Sidecar { +func (s *AgentSidecar) Bind() *AgentSidecar { s.WatchPaths = GetActualValues(s.WatchPaths) s.AutoBackupDuration = GetActualValue(s.AutoBackupDuration) s.AutoBackupDurationLimit = GetActualValue(s.AutoBackupDurationLimit) diff --git a/internal/config/sidecar_test.go b/internal/config/sidecar_test.go index be15a480e24..ce7d1e9d5c5 100644 --- a/internal/config/sidecar_test.go +++ b/internal/config/sidecar_test.go @@ -25,24 +25,24 @@ import ( "go.uber.org/goleak" ) -func TestSidecar_Bind(t *testing.T) { +func TestAgentSidecar_Bind(t *testing.T) { type fields struct { WatchPaths []string AutoBackupDurationLimit string AutoBackupDuration string } type want struct { - want *Sidecar + want *AgentSidecar } type test struct { name string fields fields want want - checkFunc func(want, *Sidecar) error + checkFunc func(want, *AgentSidecar) error beforeFunc func() afterFunc func() } - defaultCheckFunc := func(w want, got *Sidecar) error { + defaultCheckFunc := func(w want, got *AgentSidecar) error { if !reflect.DeepEqual(got, w.want) { return errors.Errorf("got = %v, want %v", got, w.want) } @@ -92,7 +92,7 @@ func TestSidecar_Bind(t *testing.T) { if test.checkFunc == nil { test.checkFunc = defaultCheckFunc } - s := &Sidecar{ + s := &AgentSidecar{ WatchPaths: test.fields.WatchPaths, AutoBackupDurationLimit: test.fields.AutoBackupDurationLimit, AutoBackupDuration: test.fields.AutoBackupDuration, diff --git a/internal/file/watch/option.go b/internal/file/watch/option.go index 8b7cdfec6bc..4b336b771d0 100644 --- a/internal/file/watch/option.go +++ b/internal/file/watch/option.go @@ -51,20 +51,6 @@ func WithDirs(dirs ...string) Option { } } -func WithDir(dir string) Option { - return func(w *watch) error { - if len(dir) == 0 { - return nil - } - if w.dirs != nil { - w.dirs = append(w.dirs, dir) - } else { - w.dirs = []string{dir} - } - return nil - } -} - func WithOnChange(f func(ctx context.Context, name string) error) Option { return func(w *watch) error { if f != nil { diff --git a/internal/file/watch/option_test.go b/internal/file/watch/option_test.go index de90aa6d234..4e3288d29a0 100644 --- a/internal/file/watch/option_test.go +++ b/internal/file/watch/option_test.go @@ -250,119 +250,6 @@ func TestWithDirs(t *testing.T) { } } -func TestWithDir(t *testing.T) { - type T = interface{} - type args struct { - dir string - } - 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.c) - } - return nil - } - */ - - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - dir: "", - }, - want: want { - obj: new(T), - }, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - dir: "", - }, - want: want { - obj: new(T), - }, - } - }(), - */ - } - - for _, test := range tests { - t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) - 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 := 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 returns 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(tt.want, obj); err != nil { - tt.Errorf("error = %v", err) - } - */ - }) - } -} - func TestWithOnChange(t *testing.T) { type T = interface{} type args struct { diff --git a/pkg/agent/sidecar/config/config.go b/pkg/agent/sidecar/config/config.go index c13dfed6adb..eb5d698055b 100644 --- a/pkg/agent/sidecar/config/config.go +++ b/pkg/agent/sidecar/config/config.go @@ -35,7 +35,7 @@ type Data struct { Observability *config.Observability `json:"observability" yaml:"observability"` // Sidecar represent agent storage sync sidecar service configuration - Sidecar *config.Sidecar `json:"sidecar" yaml:"sidecar"` + AgentSidecar *config.AgentSidecar `json:"agent_sidecar" yaml:"agent_sidecar"` } func NewConfig(path string) (cfg *Data, err error) { @@ -57,8 +57,8 @@ func NewConfig(path string) (cfg *Data, err error) { cfg.Observability = cfg.Observability.Bind() } - if cfg.Sidecar != nil { - cfg.Sidecar = cfg.Sidecar.Bind() + if cfg.AgentSidecar != nil { + cfg.AgentSidecar = cfg.AgentSidecar.Bind() } return cfg, nil } diff --git a/pkg/agent/sidecar/handler/grpc/option.go b/pkg/agent/sidecar/handler/grpc/option.go index 0ea18a48ea7..1421fff34e4 100644 --- a/pkg/agent/sidecar/handler/grpc/option.go +++ b/pkg/agent/sidecar/handler/grpc/option.go @@ -29,7 +29,7 @@ var ( func WithStorageObserver(so service.StorageObserver) Option { return func(s *server) { - if i != nil { + if so != nil { s.so = so } } diff --git a/pkg/agent/sidecar/service/option.go b/pkg/agent/sidecar/service/option.go index c0d8f9470ee..fd4c7a590e9 100644 --- a/pkg/agent/sidecar/service/option.go +++ b/pkg/agent/sidecar/service/option.go @@ -85,16 +85,3 @@ func WithDirs(dirs ...string) Option { } } -func WithDir(dir string) Option { - return func(o *observer) error { - if len(dir) == 0 { - return nil - } - if o.dirs != nil { - o.dirs = append(o.dirs, dir) - } else { - o.dirs = []string{dir} - } - return nil - } -} diff --git a/pkg/agent/sidecar/service/option_test.go b/pkg/agent/sidecar/service/option_test.go index d6aea6a7eda..a2c17d45edc 100644 --- a/pkg/agent/sidecar/service/option_test.go +++ b/pkg/agent/sidecar/service/option_test.go @@ -475,116 +475,3 @@ func TestWithDirs(t *testing.T) { }) } } - -func TestWithDir(t *testing.T) { - type T = interface{} - type args struct { - dir string - } - 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.c) - } - return nil - } - */ - - tests := []test{ - // TODO test cases - /* - { - name: "test_case_1", - args: args { - dir: "", - }, - want: want { - obj: new(T), - }, - }, - */ - - // TODO test cases - /* - func() test { - return test { - name: "test_case_2", - args: args { - dir: "", - }, - want: want { - obj: new(T), - }, - } - }(), - */ - } - - for _, test := range tests { - t.Run(test.name, func(tt *testing.T) { - defer goleak.VerifyNone(t) - 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 := 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 returns 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(tt.want, obj); err != nil { - tt.Errorf("error = %v", err) - } - */ - }) - } -} diff --git a/pkg/agent/sidecar/usecase/sidecard.go b/pkg/agent/sidecar/usecase/sidecard.go index a39b1578d2f..010d84ba609 100644 --- a/pkg/agent/sidecar/usecase/sidecard.go +++ b/pkg/agent/sidecar/usecase/sidecard.go @@ -62,9 +62,9 @@ func New(cfg *config.Data) (r runner.Runner, err error) { } so, err = service.New( service.WithErrGroup(eg), - service.WithBackupDuration(cfg.Sidecar.AutoBackupDuration), - service.WithBackupDurationLimit(cfg.Sidecar.AutoBackupDurationLimit), - service.WithDirs(cfg.Sidecar.WatchPaths...), + service.WithBackupDuration(cfg.AgentSidecar.AutoBackupDuration), + service.WithBackupDurationLimit(cfg.AgentSidecar.AutoBackupDurationLimit), + service.WithDirs(cfg.AgentSidecar.WatchPaths...), ) if err != nil { return nil, err