Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: kpango <[email protected]>
  • Loading branch information
kpango committed May 26, 2020
1 parent 376857c commit 6787380
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 267 deletions.
4 changes: 2 additions & 2 deletions internal/config/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions internal/config/sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 0 additions & 14 deletions internal/file/watch/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
113 changes: 0 additions & 113 deletions internal/file/watch/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions pkg/agent/sidecar/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/sidecar/handler/grpc/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (

func WithStorageObserver(so service.StorageObserver) Option {
return func(s *server) {
if i != nil {
if so != nil {
s.so = so
}
}
Expand Down
13 changes: 0 additions & 13 deletions pkg/agent/sidecar/service/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
113 changes: 0 additions & 113 deletions pkg/agent/sidecar/service/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
*/
})
}
}
6 changes: 3 additions & 3 deletions pkg/agent/sidecar/usecase/sidecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6787380

Please sign in to comment.