Rename org config method Update to Put for semantic accuracy
Co-authored-by: Jared Scheib <jared.scheib@gmail.com>pull/10616/head
parent
44ee2dc168
commit
6ec5d171e4
|
@ -54,7 +54,7 @@ func (s *OrganizationConfigStore) FindOrCreate(ctx context.Context, orgID string
|
|||
err := s.get(ctx, tx, orgID, &c)
|
||||
if err == chronograf.ErrOrganizationConfigNotFound {
|
||||
c = newOrganizationConfig(orgID)
|
||||
return s.update(ctx, tx, &c)
|
||||
return s.put(ctx, tx, &c)
|
||||
}
|
||||
return err
|
||||
})
|
||||
|
@ -65,14 +65,14 @@ func (s *OrganizationConfigStore) FindOrCreate(ctx context.Context, orgID string
|
|||
return &c, nil
|
||||
}
|
||||
|
||||
// Update replaces the OrganizationConfig in the store
|
||||
func (s *OrganizationConfigStore) Update(ctx context.Context, c *chronograf.OrganizationConfig) error {
|
||||
// Put replaces the OrganizationConfig in the store
|
||||
func (s *OrganizationConfigStore) Put(ctx context.Context, c *chronograf.OrganizationConfig) error {
|
||||
return s.client.db.Update(func(tx *bolt.Tx) error {
|
||||
return s.update(ctx, tx, c)
|
||||
return s.put(ctx, tx, c)
|
||||
})
|
||||
}
|
||||
|
||||
func (s *OrganizationConfigStore) update(ctx context.Context, tx *bolt.Tx, c *chronograf.OrganizationConfig) error {
|
||||
func (s *OrganizationConfigStore) put(ctx context.Context, tx *bolt.Tx, c *chronograf.OrganizationConfig) error {
|
||||
if c == nil {
|
||||
return fmt.Errorf("config provided was nil")
|
||||
}
|
||||
|
|
|
@ -661,7 +661,7 @@ func TestOrganizationConfig_FindOrCreate(t *testing.T) {
|
|||
s := client.OrganizationConfigStore
|
||||
|
||||
if tt.addFirst {
|
||||
if err := s.Update(context.Background(), tt.wants.organizationConfig); err != nil {
|
||||
if err := s.Put(context.Background(), tt.wants.organizationConfig); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
@ -686,7 +686,7 @@ func TestOrganizationConfig_FindOrCreate(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestOrganizationConfig_Update(t *testing.T) {
|
||||
func TestOrganizationConfig_Put(t *testing.T) {
|
||||
type args struct {
|
||||
organizationConfig *chronograf.OrganizationConfig
|
||||
organizationID string
|
||||
|
@ -1141,20 +1141,20 @@ func TestOrganizationConfig_Update(t *testing.T) {
|
|||
defer client.Close()
|
||||
|
||||
s := client.OrganizationConfigStore
|
||||
err = s.Update(context.Background(), tt.args.organizationConfig)
|
||||
err = s.Put(context.Background(), tt.args.organizationConfig)
|
||||
if (tt.wants.err != nil) != (err != nil) {
|
||||
t.Errorf("%q. OrganizationConfigStore.Update() error = %v, wantErr %v", tt.name, err, tt.wants.err)
|
||||
t.Errorf("%q. OrganizationConfigStore.Put() error = %v, wantErr %v", tt.name, err, tt.wants.err)
|
||||
continue
|
||||
}
|
||||
|
||||
got, _ := s.FindOrCreate(context.Background(), tt.args.organizationID)
|
||||
if (tt.wants.err != nil) != (err != nil) {
|
||||
t.Errorf("%q. OrganizationConfigStore.Update() error = %v, wantErr %v", tt.name, err, tt.wants.err)
|
||||
t.Errorf("%q. OrganizationConfigStore.Put() error = %v, wantErr %v", tt.name, err, tt.wants.err)
|
||||
continue
|
||||
}
|
||||
|
||||
if diff := cmp.Diff(got, tt.wants.organizationConfig); diff != "" {
|
||||
t.Errorf("%q. OrganizationConfigStore.Update():\n-got/+want\ndiff %s", tt.name, diff)
|
||||
t.Errorf("%q. OrganizationConfigStore.Put():\n-got/+want\ndiff %s", tt.name, diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -789,8 +789,8 @@ type ColumnEncoding struct {
|
|||
type OrganizationConfigStore interface {
|
||||
// FindOrCreate gets an existing OrganizationConfig and creates one if none exists
|
||||
FindOrCreate(ctx context.Context, orgID string) (*OrganizationConfig, error)
|
||||
// Update updates the whole organization config in the OrganizationConfigStore
|
||||
Update(context.Context, *OrganizationConfig) error
|
||||
// Put replaces the whole organization config in the OrganizationConfigStore
|
||||
Put(context.Context, *OrganizationConfig) error
|
||||
}
|
||||
|
||||
// BuildInfo is sent to the usage client to track versions and commits
|
||||
|
|
|
@ -10,13 +10,13 @@ var _ chronograf.OrganizationConfigStore = &OrganizationConfigStore{}
|
|||
|
||||
type OrganizationConfigStore struct {
|
||||
FindOrCreateF func(ctx context.Context, id string) (*chronograf.OrganizationConfig, error)
|
||||
UpdateF func(ctx context.Context, target *chronograf.OrganizationConfig) error
|
||||
PutF func(ctx context.Context, c *chronograf.OrganizationConfig) error
|
||||
}
|
||||
|
||||
func (s *OrganizationConfigStore) FindOrCreate(ctx context.Context, id string) (*chronograf.OrganizationConfig, error) {
|
||||
return s.FindOrCreateF(ctx, id)
|
||||
}
|
||||
|
||||
func (s *OrganizationConfigStore) Update(ctx context.Context, target *chronograf.OrganizationConfig) error {
|
||||
return s.UpdateF(ctx, target)
|
||||
func (s *OrganizationConfigStore) Put(ctx context.Context, c *chronograf.OrganizationConfig) error {
|
||||
return s.PutF(ctx, c)
|
||||
}
|
||||
|
|
|
@ -16,6 +16,6 @@ func (s *OrganizationConfigStore) FindOrCreate(context.Context, string) (*chrono
|
|||
return nil, chronograf.ErrOrganizationConfigNotFound
|
||||
}
|
||||
|
||||
func (s *OrganizationConfigStore) Update(context.Context, *chronograf.OrganizationConfig) error {
|
||||
return fmt.Errorf("cannot update conifg")
|
||||
func (s *OrganizationConfigStore) Put(context.Context, *chronograf.OrganizationConfig) error {
|
||||
return fmt.Errorf("cannot replace config")
|
||||
}
|
||||
|
|
|
@ -40,12 +40,12 @@ func (s *OrganizationConfigStore) FindOrCreate(ctx context.Context, orgID string
|
|||
|
||||
}
|
||||
|
||||
// Update the OrganizationConfig in OrganizationConfigStore.
|
||||
func (s *OrganizationConfigStore) Update(ctx context.Context, c *chronograf.OrganizationConfig) error {
|
||||
// Put the OrganizationConfig in OrganizationConfigStore.
|
||||
func (s *OrganizationConfigStore) Put(ctx context.Context, c *chronograf.OrganizationConfig) error {
|
||||
err := validOrganization(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return s.store.Update(ctx, c)
|
||||
return s.store.Put(ctx, c)
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ func (s *Service) ReplaceOrganizationLogViewerConfig(w http.ResponseWriter, r *h
|
|||
return
|
||||
}
|
||||
config.LogViewer = logViewerConfig
|
||||
if err := s.Store.OrganizationConfig(ctx).Update(ctx, config); err != nil {
|
||||
if err := s.Store.OrganizationConfig(ctx).Put(ctx, config); err != nil {
|
||||
unknownErrorWithMessage(w, err, s.Logger)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -356,7 +356,7 @@ func TestReplaceLogViewerOrganizationConfig(t *testing.T) {
|
|||
return nil, chronograf.ErrOrganizationConfigNotFound
|
||||
}
|
||||
},
|
||||
UpdateF: func(ctx context.Context, target *chronograf.OrganizationConfig) error {
|
||||
PutF: func(ctx context.Context, target *chronograf.OrganizationConfig) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
|
@ -448,7 +448,7 @@ func TestReplaceLogViewerOrganizationConfig(t *testing.T) {
|
|||
return nil, chronograf.ErrOrganizationConfigNotFound
|
||||
}
|
||||
},
|
||||
UpdateF: func(ctx context.Context, target *chronograf.OrganizationConfig) error {
|
||||
PutF: func(ctx context.Context, target *chronograf.OrganizationConfig) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
|
@ -492,7 +492,7 @@ func TestReplaceLogViewerOrganizationConfig(t *testing.T) {
|
|||
return nil, chronograf.ErrOrganizationConfigNotFound
|
||||
}
|
||||
},
|
||||
UpdateF: func(ctx context.Context, target *chronograf.OrganizationConfig) error {
|
||||
PutF: func(ctx context.Context, target *chronograf.OrganizationConfig) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
|
@ -557,7 +557,7 @@ func TestReplaceLogViewerOrganizationConfig(t *testing.T) {
|
|||
return nil, chronograf.ErrOrganizationConfigNotFound
|
||||
}
|
||||
},
|
||||
UpdateF: func(ctx context.Context, target *chronograf.OrganizationConfig) error {
|
||||
PutF: func(ctx context.Context, target *chronograf.OrganizationConfig) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
|
@ -627,7 +627,7 @@ func TestReplaceLogViewerOrganizationConfig(t *testing.T) {
|
|||
return nil, chronograf.ErrOrganizationConfigNotFound
|
||||
}
|
||||
},
|
||||
UpdateF: func(ctx context.Context, target *chronograf.OrganizationConfig) error {
|
||||
PutF: func(ctx context.Context, target *chronograf.OrganizationConfig) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue