Merge pull request #19597 from influxdata/rogpeppe-004-avoid-nil-context
fix: chronograf/organizations: avoid nil context with WithValuepull/19559/head
commit
62af80f418
|
@ -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)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue