Merge pull request #19597 from influxdata/rogpeppe-004-avoid-nil-context

fix: chronograf/organizations: avoid nil context with WithValue
pull/19559/head
Roger Peppe 2020-09-22 16:16:26 +01:00 committed by GitHub
commit 62af80f418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 25 deletions

View File

@ -25,7 +25,6 @@ func TestDashboards_All(t *testing.T) {
}
type args struct {
organization string
ctx context.Context
}
tests := []struct {
name string
@ -65,7 +64,6 @@ func TestDashboards_All(t *testing.T) {
},
args: args{
organization: "1337",
ctx: context.Background(),
},
want: []chronograf.Dashboard{
{
@ -76,18 +74,20 @@ func TestDashboards_All(t *testing.T) {
},
}
for _, tt := range tests {
s := organizations.NewDashboardsStore(tt.fields.DashboardsStore, tt.args.organization)
tt.args.ctx = context.WithValue(tt.args.ctx, organizations.ContextKey, tt.args.organization)
gots, err := s.All(tt.args.ctx)
if (err != nil) != tt.wantErr {
t.Errorf("%q. DashboardsStore.All() error = %v, wantErr %v", tt.name, err, tt.wantErr)
continue
}
for i, got := range gots {
if diff := cmp.Diff(got, tt.want[i], dashboardCmpOptions...); diff != "" {
t.Errorf("%q. DashboardsStore.All():\n-got/+want\ndiff %s", tt.name, diff)
t.Run(tt.name, func(t *testing.T) {
s := organizations.NewDashboardsStore(tt.fields.DashboardsStore, tt.args.organization)
ctx := context.WithValue(context.Background(), organizations.ContextKey, tt.args.organization)
gots, err := s.All(ctx)
if (err != nil) != tt.wantErr {
t.Errorf("%q. DashboardsStore.All() error = %v, wantErr %v", tt.name, err, tt.wantErr)
return
}
}
for i, got := range gots {
if diff := cmp.Diff(got, tt.want[i], dashboardCmpOptions...); diff != "" {
t.Errorf("%q. DashboardsStore.All():\n-got/+want\ndiff %s", tt.name, diff)
}
}
})
}
}

View File

@ -25,7 +25,6 @@ func TestOrganizations_All(t *testing.T) {
}
type args struct {
organization string
ctx context.Context
}
tests := []struct {
name string
@ -77,7 +76,6 @@ func TestOrganizations_All(t *testing.T) {
},
args: args{
organization: "1337",
ctx: context.Background(),
},
want: []chronograf.Organization{
{
@ -93,8 +91,8 @@ func TestOrganizations_All(t *testing.T) {
}
for _, tt := range tests {
s := organizations.NewOrganizationsStore(tt.fields.OrganizationsStore, tt.args.organization)
tt.args.ctx = context.WithValue(tt.args.ctx, organizations.ContextKey, tt.args.organization)
gots, err := s.All(tt.args.ctx)
ctx := context.WithValue(context.Background(), organizations.ContextKey, tt.args.organization)
gots, err := s.All(ctx)
if (err != nil) != tt.wantErr {
t.Errorf("%q. OrganizationsStore.All() error = %v, wantErr %v", tt.name, err, tt.wantErr)
continue

View File

@ -26,7 +26,6 @@ func TestServers_All(t *testing.T) {
}
type args struct {
organization string
ctx context.Context
}
tests := []struct {
name string
@ -66,7 +65,6 @@ func TestServers_All(t *testing.T) {
},
args: args{
organization: "1337",
ctx: context.Background(),
},
want: []chronograf.Server{
{
@ -78,8 +76,8 @@ func TestServers_All(t *testing.T) {
}
for _, tt := range tests {
s := organizations.NewServersStore(tt.fields.ServersStore, tt.args.organization)
tt.args.ctx = context.WithValue(tt.args.ctx, organizations.ContextKey, tt.args.organization)
gots, err := s.All(tt.args.ctx)
ctx := context.WithValue(context.Background(), organizations.ContextKey, tt.args.organization)
gots, err := s.All(ctx)
if (err != nil) != tt.wantErr {
t.Errorf("%q. ServersStore.All() error = %v, wantErr %v", tt.name, err, tt.wantErr)
continue

View File

@ -26,7 +26,6 @@ func TestSources_All(t *testing.T) {
}
type args struct {
organization string
ctx context.Context
}
tests := []struct {
name string
@ -66,7 +65,6 @@ func TestSources_All(t *testing.T) {
},
args: args{
organization: "1337",
ctx: context.Background(),
},
want: []chronograf.Source{
{
@ -78,8 +76,8 @@ func TestSources_All(t *testing.T) {
}
for _, tt := range tests {
s := organizations.NewSourcesStore(tt.fields.SourcesStore, tt.args.organization)
tt.args.ctx = context.WithValue(tt.args.ctx, organizations.ContextKey, tt.args.organization)
gots, err := s.All(tt.args.ctx)
ctx := context.WithValue(context.Background(), organizations.ContextKey, tt.args.organization)
gots, err := s.All(ctx)
if (err != nil) != tt.wantErr {
t.Errorf("%q. SourcesStore.All() error = %v, wantErr %v", tt.name, err, tt.wantErr)
continue