remove colors from labels

pull/10616/head
Jade McGough 2018-12-20 12:18:03 -08:00
parent 53f27c5566
commit 1a10ae701a
6 changed files with 170 additions and 225 deletions

View File

@ -185,10 +185,6 @@ func (c *Client) updateLabel(ctx context.Context, tx *bolt.Tx, l *platform.Label
label := ls[0]
if upd.Color != nil {
label.Color = *upd.Color
}
if err := label.Validate(); err != nil {
return nil, &platform.Error{
Code: platform.EInvalid,

View File

@ -6574,8 +6574,7 @@ components:
properties:
name:
type: string
color:
type: string
description: A six-character hex color.
pattern: '^([A-Fa-f0-9]{6})$'
example: 'ffb3b3'
properties:
type: object
description: Key/Value pairs associated with this label.
example: {color: ffb3b3, description: "this is a description"}

View File

@ -106,10 +106,6 @@ func (s *Service) UpdateLabel(ctx context.Context, l *platform.Label, upd platfo
}
}
if upd.Color != nil {
label.Color = *upd.Color
}
if err := label.Validate(); err != nil {
return nil, &platform.Error{
Code: platform.EInvalid,

View File

@ -2,7 +2,6 @@ package platform
import (
"context"
"regexp"
)
// ErrLabelNotFound is the error for a missing Label.
@ -15,8 +14,6 @@ const (
OpDeleteLabel = "DeleteLabel"
)
var colorPattern = regexp.MustCompile(`^([A-Fa-f0-9]{6})$`)
type LabelService interface {
// FindLabels returns a list of labels that match a filter
FindLabels(ctx context.Context, filter LabelFilter, opt ...FindOptions) ([]*Label, error)
@ -34,7 +31,6 @@ type LabelService interface {
type Label struct {
ResourceID ID `json:"resource_id"`
Name string `json:"name"`
Color string `json:"color"`
}
// Validate returns an error if the label is invalid.
@ -53,31 +49,13 @@ func (l *Label) Validate() error {
}
}
if l.Color != "" && !colorPattern.MatchString(l.Color) {
return &Error{
Code: EInvalid,
Msg: "label color must be valid hex string",
}
}
return nil
}
// LabelUpdate represents a changeset for a label.
// Only fields which are set are updated.
type LabelUpdate struct {
Color *string `json:"color,omitempty"`
}
func (l *LabelUpdate) Validate() error {
if *l.Color != "" && !colorPattern.MatchString(*l.Color) {
return &Error{
Code: EInvalid,
Msg: "label color must be valid hex string",
}
}
return nil
// Color *string `json:"color,omitempty"`
}
type LabelFilter struct {

View File

@ -11,7 +11,6 @@ func TestLabelValidate(t *testing.T) {
type fields struct {
ResourceID platform.ID
Name string
Color string
}
tests := []struct {
name string
@ -39,30 +38,12 @@ func TestLabelValidate(t *testing.T) {
},
wantErr: true,
},
{
name: "label can have a color",
fields: fields{
ResourceID: platformtesting.MustIDBase16("020f755c3c082000"),
Name: "iot",
Color: "ff0000",
},
},
{
name: "label color must be valid hex string",
fields: fields{
ResourceID: platformtesting.MustIDBase16("020f755c3c082000"),
Name: "iot",
Color: "invalid",
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
m := platform.Label{
ResourceID: tt.fields.ResourceID,
Name: tt.fields.Name,
Color: tt.fields.Color,
}
if err := m.Validate(); (err != nil) != tt.wantErr {
t.Errorf("Label.Validate() error = %v, wantErr %v", err, tt.wantErr)

View File

@ -10,11 +10,6 @@ import (
"github.com/influxdata/platform"
)
var (
validColor = "fff000"
invalidColor = "xyz123"
)
var labelCmpOptions = cmp.Options{
cmp.Comparer(func(x, y []byte) bool {
return bytes.Equal(x, y)
@ -57,10 +52,10 @@ func LabelService(
name: "FindLabels",
fn: FindLabels,
},
{
name: "UpdateLabel",
fn: UpdateLabel,
},
// {
// name: "UpdateLabel",
// fn: UpdateLabel,
// },
{
name: "DeleteLabel",
fn: DeleteLabel,
@ -271,167 +266,167 @@ func FindLabels(
}
}
func UpdateLabel(
init func(LabelFields, *testing.T) (platform.LabelService, string, func()),
t *testing.T,
) {
type args struct {
label platform.Label
update platform.LabelUpdate
}
type wants struct {
err error
labels []*platform.Label
}
tests := []struct {
name string
fields LabelFields
args args
wants wants
}{
{
name: "update label color",
fields: LabelFields{
Labels: []*platform.Label{
{
ResourceID: MustIDBase16(bucketOneID),
Name: "Tag1",
},
},
},
args: args{
label: platform.Label{
ResourceID: MustIDBase16(bucketOneID),
Name: "Tag1",
},
update: platform.LabelUpdate{
Color: &validColor,
},
},
wants: wants{
labels: []*platform.Label{
{
ResourceID: MustIDBase16(bucketOneID),
Name: "Tag1",
Color: "fff000",
},
},
},
},
// {
// name: "label update proliferation",
// fields: LabelFields{
// Labels: []*platform.Label{
// {
// ResourceID: MustIDBase16(bucketOneID),
// Name: "Tag1",
// },
// {
// ResourceID: MustIDBase16(bucketTwoID),
// Name: "Tag1",
// },
// },
// },
// args: args{
// label: platform.Label{
// ResourceID: MustIDBase16(bucketOneID),
// Name: "Tag1",
// },
// update: platform.LabelUpdate{
// Color: &validColor,
// },
// },
// wants: wants{
// labels: []*platform.Label{
// {
// ResourceID: MustIDBase16(bucketOneID),
// Name: "Tag1",
// Color: "fff000",
// },
// {
// ResourceID: MustIDBase16(bucketTwoID),
// Name: "Tag1",
// Color: "fff000",
// },
// },
// },
// },
{
name: "invalid label color update",
fields: LabelFields{
Labels: []*platform.Label{
{
ResourceID: MustIDBase16(bucketOneID),
Name: "Tag1",
},
},
},
args: args{
label: platform.Label{
ResourceID: MustIDBase16(bucketOneID),
Name: "Tag1",
},
update: platform.LabelUpdate{
Color: &invalidColor,
},
},
wants: wants{
labels: []*platform.Label{
{
ResourceID: MustIDBase16(bucketOneID),
Name: "Tag1",
},
},
err: &platform.Error{
Code: platform.EInvalid,
Op: platform.OpUpdateLabel,
Msg: "label color must be valid hex string",
},
},
},
{
name: "updating a non-existent label",
fields: LabelFields{
Labels: []*platform.Label{},
},
args: args{
label: platform.Label{
ResourceID: MustIDBase16(bucketOneID),
Name: "Tag1",
},
update: platform.LabelUpdate{
Color: &validColor,
},
},
wants: wants{
labels: []*platform.Label{},
err: &platform.Error{
Code: platform.ENotFound,
Op: platform.OpUpdateLabel,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s, opPrefix, done := init(tt.fields, t)
defer done()
ctx := context.TODO()
_, err := s.UpdateLabel(ctx, &tt.args.label, tt.args.update)
diffPlatformErrors(tt.name, err, tt.wants.err, opPrefix, t)
labels, err := s.FindLabels(ctx, platform.LabelFilter{})
if err != nil {
t.Fatalf("failed to retrieve labels: %v", err)
}
if diff := cmp.Diff(labels, tt.wants.labels, labelCmpOptions...); diff != "" {
t.Errorf("labels are different -got/+want\ndiff %s", diff)
}
})
}
}
// func UpdateLabel(
// init func(LabelFields, *testing.T) (platform.LabelService, string, func()),
// t *testing.T,
// ) {
// type args struct {
// label platform.Label
// update platform.LabelUpdate
// }
// type wants struct {
// err error
// labels []*platform.Label
// }
//
// tests := []struct {
// name string
// fields LabelFields
// args args
// wants wants
// }{
// {
// name: "update label color",
// fields: LabelFields{
// Labels: []*platform.Label{
// {
// ResourceID: MustIDBase16(bucketOneID),
// Name: "Tag1",
// },
// },
// },
// args: args{
// label: platform.Label{
// ResourceID: MustIDBase16(bucketOneID),
// Name: "Tag1",
// },
// update: platform.LabelUpdate{
// Color: &validColor,
// },
// },
// wants: wants{
// labels: []*platform.Label{
// {
// ResourceID: MustIDBase16(bucketOneID),
// Name: "Tag1",
// Color: "fff000",
// },
// },
// },
// },
// // {
// // name: "label update proliferation",
// // fields: LabelFields{
// // Labels: []*platform.Label{
// // {
// // ResourceID: MustIDBase16(bucketOneID),
// // Name: "Tag1",
// // },
// // {
// // ResourceID: MustIDBase16(bucketTwoID),
// // Name: "Tag1",
// // },
// // },
// // },
// // args: args{
// // label: platform.Label{
// // ResourceID: MustIDBase16(bucketOneID),
// // Name: "Tag1",
// // },
// // update: platform.LabelUpdate{
// // Color: &validColor,
// // },
// // },
// // wants: wants{
// // labels: []*platform.Label{
// // {
// // ResourceID: MustIDBase16(bucketOneID),
// // Name: "Tag1",
// // Color: "fff000",
// // },
// // {
// // ResourceID: MustIDBase16(bucketTwoID),
// // Name: "Tag1",
// // Color: "fff000",
// // },
// // },
// // },
// // },
// {
// name: "invalid label color update",
// fields: LabelFields{
// Labels: []*platform.Label{
// {
// ResourceID: MustIDBase16(bucketOneID),
// Name: "Tag1",
// },
// },
// },
// args: args{
// label: platform.Label{
// ResourceID: MustIDBase16(bucketOneID),
// Name: "Tag1",
// },
// update: platform.LabelUpdate{
// Color: &invalidColor,
// },
// },
// wants: wants{
// labels: []*platform.Label{
// {
// ResourceID: MustIDBase16(bucketOneID),
// Name: "Tag1",
// },
// },
// err: &platform.Error{
// Code: platform.EInvalid,
// Op: platform.OpUpdateLabel,
// Msg: "label color must be valid hex string",
// },
// },
// },
// {
// name: "updating a non-existent label",
// fields: LabelFields{
// Labels: []*platform.Label{},
// },
// args: args{
// label: platform.Label{
// ResourceID: MustIDBase16(bucketOneID),
// Name: "Tag1",
// },
// update: platform.LabelUpdate{
// Color: &validColor,
// },
// },
// wants: wants{
// labels: []*platform.Label{},
// err: &platform.Error{
// Code: platform.ENotFound,
// Op: platform.OpUpdateLabel,
// },
// },
// },
// }
//
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// s, opPrefix, done := init(tt.fields, t)
// defer done()
// ctx := context.TODO()
// _, err := s.UpdateLabel(ctx, &tt.args.label, tt.args.update)
// diffPlatformErrors(tt.name, err, tt.wants.err, opPrefix, t)
//
// labels, err := s.FindLabels(ctx, platform.LabelFilter{})
// if err != nil {
// t.Fatalf("failed to retrieve labels: %v", err)
// }
// if diff := cmp.Diff(labels, tt.wants.labels, labelCmpOptions...); diff != "" {
// t.Errorf("labels are different -got/+want\ndiff %s", diff)
// }
// })
// }
// }
func DeleteLabel(
init func(LabelFields, *testing.T) (platform.LabelService, string, func()),