From d3bcfb893693779152cf0522d1e154b10d71dd32 Mon Sep 17 00:00:00 2001 From: kpango Date: Tue, 26 May 2020 10:33:50 +0900 Subject: [PATCH] fix Signed-off-by: kpango --- go.mod | 4 +- go.sum | 8 +- internal/config/sidecar.go | 4 +- internal/config/sidecar_test.go | 10 +- internal/file/watch/option.go | 14 --- internal/file/watch/option_test.go | 113 ------------------ pkg/agent/sidecar/config/config.go | 6 +- .../sidecar/handler/grpc/handler_test.go | 2 +- pkg/agent/sidecar/handler/grpc/option.go | 2 +- .../sidecar/handler/rest/handler_test.go | 2 +- pkg/agent/sidecar/service/option.go | 14 --- pkg/agent/sidecar/service/option_test.go | 113 ------------------ pkg/agent/sidecar/usecase/sidecard.go | 6 +- pkg/agent/sidecar/usecase/sidecard_test.go | 2 +- 14 files changed, 24 insertions(+), 276 deletions(-) diff --git a/go.mod b/go.mod index 1f97f06c0e..d5c33df82e 100755 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ replace ( github.com/coreos/etcd => go.etcd.io/etcd v0.5.0-alpha.5.0.20200425165423-262c93980547 github.com/docker/docker => github.com/moby/moby v17.12.0-ce-rc1.0.20200309214505-aa6a9891b09c+incompatible github.com/envoyproxy/protoc-gen-validate => github.com/envoyproxy/protoc-gen-validate v0.3.0-java - github.com/go-sql-driver/mysql => github.com/go-sql-driver/mysql v1.5.1-0.20200521132419-128a6737a202 + github.com/go-sql-driver/mysql => github.com/go-sql-driver/mysql v1.5.1-0.20200525102840-8c3a2d9049b4 github.com/gocql/gocql => github.com/gocql/gocql v0.0.0-20200519160334-799061058e31 github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.1 github.com/gophercloud/gophercloud => github.com/gophercloud/gophercloud v0.11.0 @@ -32,7 +32,7 @@ require ( github.com/cockroachdb/errors v0.0.0-00010101000000-000000000000 github.com/danielvladco/go-proto-gql/pb v0.6.1 github.com/envoyproxy/protoc-gen-validate v0.1.0 - github.com/fsnotify/fsnotify v1.4.7 + github.com/fsnotify/fsnotify v1.4.9 github.com/go-redis/redis/v7 v7.3.0 github.com/go-sql-driver/mysql v1.5.0 github.com/gocql/gocql v0.0.0-20200131111108-92af2e088537 diff --git a/go.sum b/go.sum index 56dddec0f1..245b2e78a5 100644 --- a/go.sum +++ b/go.sum @@ -151,8 +151,9 @@ github.com/fortytw2/leaktest v1.2.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHqu github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/frankban/quicktest v1.4.0 h1:rCSCih1FnSWJEel/eub9wclBSqpF2F/PuvxUWGWnbO8= github.com/frankban/quicktest v1.4.0/go.mod h1:36zfPVQyHxymz4cH7wlDmVwDrJuljRB60qkgn7rorfQ= -github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/gavv/httpexpect v2.0.0+incompatible/go.mod h1:x+9tiU1YnrOvnB725RkpoLv1M62hOWzwo5OXotisrKc= github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -218,8 +219,8 @@ github.com/go-redis/redis v6.15.2+incompatible h1:9SpNVG76gr6InJGxoZ6IuuxaCOQwDA github.com/go-redis/redis v6.15.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= github.com/go-redis/redis/v7 v7.3.0 h1:3oHqd0W7f/VLKBxeYTEpqdMUsmMectngjM9OtoRoIgg= github.com/go-redis/redis/v7 v7.3.0/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg= -github.com/go-sql-driver/mysql v1.5.1-0.20200521132419-128a6737a202 h1:MVqCQqO9Y9V3LM1TwbOGOuLqlBWiU+TjjMH/M/PfGiw= -github.com/go-sql-driver/mysql v1.5.1-0.20200521132419-128a6737a202/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-sql-driver/mysql v1.5.1-0.20200525102840-8c3a2d9049b4 h1:EwVyKWAXcaG1sJdJu+D7NlZ5WZdze/plTXEBHPrf2mk= +github.com/go-sql-driver/mysql v1.5.1-0.20200525102840-8c3a2d9049b4/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= @@ -681,6 +682,7 @@ golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/internal/config/sidecar.go b/internal/config/sidecar.go index aaf5a7cf0b..96519a6ddd 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 be15a480e2..ce7d1e9d5c 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 8b7cdfec6b..4b336b771d 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 de90aa6d23..4e3288d29a 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 c13dfed6ad..eb5d698055 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/handler_test.go b/pkg/agent/sidecar/handler/grpc/handler_test.go index 198c039939..81ebd95bbe 100644 --- a/pkg/agent/sidecar/handler/grpc/handler_test.go +++ b/pkg/agent/sidecar/handler/grpc/handler_test.go @@ -21,8 +21,8 @@ import ( "reflect" "testing" - "github.com/vdaas/vald/internal/errors" "github.com/vdaas/vald/apis/grpc/agent/sidecar" + "github.com/vdaas/vald/internal/errors" "go.uber.org/goleak" ) diff --git a/pkg/agent/sidecar/handler/grpc/option.go b/pkg/agent/sidecar/handler/grpc/option.go index 0ea18a48ea..1421fff34e 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/handler/rest/handler_test.go b/pkg/agent/sidecar/handler/rest/handler_test.go index 8e6e06f42b..8fc6c65f7f 100644 --- a/pkg/agent/sidecar/handler/rest/handler_test.go +++ b/pkg/agent/sidecar/handler/rest/handler_test.go @@ -22,8 +22,8 @@ import ( "reflect" "testing" - "github.com/vdaas/vald/internal/errors" "github.com/vdaas/vald/apis/grpc/agent/sidecar" + "github.com/vdaas/vald/internal/errors" "go.uber.org/goleak" ) diff --git a/pkg/agent/sidecar/service/option.go b/pkg/agent/sidecar/service/option.go index c0d8f9470e..0440c2b51c 100644 --- a/pkg/agent/sidecar/service/option.go +++ b/pkg/agent/sidecar/service/option.go @@ -84,17 +84,3 @@ func WithDirs(dirs ...string) Option { return nil } } - -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 d6aea6a7ed..a2c17d45ed 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 a39b1578d2..010d84ba60 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 diff --git a/pkg/agent/sidecar/usecase/sidecard_test.go b/pkg/agent/sidecar/usecase/sidecard_test.go index c41611085a..4d071c30f3 100644 --- a/pkg/agent/sidecar/usecase/sidecard_test.go +++ b/pkg/agent/sidecar/usecase/sidecard_test.go @@ -21,8 +21,8 @@ import ( "reflect" "testing" - "github.com/vdaas/vald/internal/errors" "github.com/vdaas/vald/internal/errgroup" + "github.com/vdaas/vald/internal/errors" "github.com/vdaas/vald/internal/observability" "github.com/vdaas/vald/internal/runner" "github.com/vdaas/vald/internal/servers/starter"