Add DashboardOrganization tests
parent
2b7cdbfe07
commit
8288f97dd6
|
@ -68,10 +68,10 @@ func (s *OrganizationDashboardsStore) Get(ctx context.Context, id chronograf.Das
|
|||
}
|
||||
|
||||
func (s *OrganizationDashboardsStore) Update(ctx context.Context, d chronograf.Dashboard) error {
|
||||
dash, err := s.client.DashboardsStore.Get(ctx, d.ID)
|
||||
_, err := s.client.DashboardsStore.Get(ctx, d.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return s.client.DashboardsStore.Update(ctx, dash)
|
||||
return s.client.DashboardsStore.Update(ctx, d)
|
||||
}
|
||||
|
|
|
@ -13,15 +13,16 @@ import (
|
|||
// EquateEmpty is used because we want nil slices, arrays, and maps to be equal to the empty map
|
||||
var dashboardCmpOptions = cmp.Options{
|
||||
cmpopts.EquateEmpty(),
|
||||
cmpopts.IgnoreFields(chronograf.Dashboard{}, "ID"),
|
||||
}
|
||||
|
||||
func TestOrganizationDashboards_All(t *testing.T) {
|
||||
type args struct {
|
||||
organization string
|
||||
ctx context.Context
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
ctx context.Context
|
||||
args args
|
||||
want []chronograf.Dashboard
|
||||
wantRaw []chronograf.Dashboard
|
||||
|
@ -29,48 +30,29 @@ func TestOrganizationDashboards_All(t *testing.T) {
|
|||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "No Dashboards",
|
||||
name: "No Dashboards",
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "All Dashbaords",
|
||||
args: {
|
||||
args: args{
|
||||
organization: "1337",
|
||||
ctx: context.Background(),
|
||||
},
|
||||
want: []chronograf.User{
|
||||
want: []chronograf.Dashboard{
|
||||
{
|
||||
Name: "howdy",
|
||||
Provider: "github",
|
||||
Scheme: "oauth2",
|
||||
Organization: "1337",
|
||||
Roles: []chronograf.Role{
|
||||
{
|
||||
Name: "viewer",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantRaw: []chronograf.User{
|
||||
wantRaw: []chronograf.Dashboard{
|
||||
{
|
||||
Name: "howdy",
|
||||
Provider: "github",
|
||||
Scheme: "oauth2",
|
||||
Organization: "1337",
|
||||
Roles: []chronograf.Role{
|
||||
{
|
||||
Name: "viewer",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "doody",
|
||||
Provider: "github",
|
||||
Scheme: "oauth2",
|
||||
Organization: "1338",
|
||||
Roles: []chronograf.Role{
|
||||
{
|
||||
Name: "editor",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
addFirst: true,
|
||||
|
@ -86,21 +68,240 @@ func TestOrganizationDashboards_All(t *testing.T) {
|
|||
}
|
||||
defer client.Close()
|
||||
|
||||
s := client.OrganizationDashboards
|
||||
s := client.OrganizationDashboardsStore
|
||||
if tt.addFirst {
|
||||
for _, u := range tt.want {
|
||||
client.DashboardsStore.Add(tt.ctx, &u)
|
||||
for _, d := range tt.wantRaw {
|
||||
client.DashboardsStore.Add(tt.args.ctx, d)
|
||||
}
|
||||
}
|
||||
gots, err := s.All(tt.ctx)
|
||||
tt.args.ctx = context.WithValue(tt.args.ctx, "organizationID", tt.args.organization)
|
||||
gots, err := s.All(tt.args.ctx)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("%q. OrganizationDashboardsStore.All() error = %v, wantErr %v", tt.name, err, tt.wantErr)
|
||||
continue
|
||||
}
|
||||
for i, got := range gots {
|
||||
if diff := cmp.Diff(got, tt.want[i], cmpOptions...); diff != "" {
|
||||
if diff := cmp.Diff(got, tt.want[i], dashboardCmpOptions...); diff != "" {
|
||||
t.Errorf("%q. OrganizationDashboardsStore.All():\n-got/+want\ndiff %s", tt.name, diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestOrganizationDashboards_Add(t *testing.T) {
|
||||
type args struct {
|
||||
organization string
|
||||
ctx context.Context
|
||||
dashboard chronograf.Dashboard
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want chronograf.Dashboard
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "Add Dashbaord",
|
||||
args: args{
|
||||
organization: "1337",
|
||||
ctx: context.Background(),
|
||||
dashboard: chronograf.Dashboard{
|
||||
Name: "howdy",
|
||||
},
|
||||
},
|
||||
want: chronograf.Dashboard{
|
||||
Name: "howdy",
|
||||
Organization: "1337",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
client, err := NewTestClient()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := client.Open(context.TODO()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
s := client.OrganizationDashboardsStore
|
||||
tt.args.ctx = context.WithValue(tt.args.ctx, "organizationID", tt.args.organization)
|
||||
d, err := s.Add(tt.args.ctx, tt.args.dashboard)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("%q. OrganizationDashboardsStore.Add() error = %v, wantErr %v", tt.name, err, tt.wantErr)
|
||||
continue
|
||||
}
|
||||
got, err := s.Get(tt.args.ctx, d.ID)
|
||||
if diff := cmp.Diff(got, tt.want, dashboardCmpOptions...); diff != "" {
|
||||
t.Errorf("%q. OrganizationDashboardsStore.Add():\n-got/+want\ndiff %s", tt.name, diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestOrganizationDashboards_Delete(t *testing.T) {
|
||||
type args struct {
|
||||
organization string
|
||||
ctx context.Context
|
||||
dashboard chronograf.Dashboard
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []chronograf.Dashboard
|
||||
addFirst bool
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "Delete dashboard",
|
||||
args: args{
|
||||
organization: "1337",
|
||||
ctx: context.Background(),
|
||||
dashboard: chronograf.Dashboard{
|
||||
Name: "howdy",
|
||||
Organization: "1337",
|
||||
},
|
||||
},
|
||||
addFirst: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
client, err := NewTestClient()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := client.Open(context.TODO()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
s := client.OrganizationDashboardsStore
|
||||
if tt.addFirst {
|
||||
tt.args.dashboard, _ = client.DashboardsStore.Add(tt.args.ctx, tt.args.dashboard)
|
||||
}
|
||||
tt.args.ctx = context.WithValue(tt.args.ctx, "organizationID", tt.args.organization)
|
||||
err = s.Delete(tt.args.ctx, tt.args.dashboard)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("%q. OrganizationDashboardsStore.All() error = %v, wantErr %v", tt.name, err, tt.wantErr)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestOrganizationDashboards_Get(t *testing.T) {
|
||||
type args struct {
|
||||
organization string
|
||||
ctx context.Context
|
||||
dashboard chronograf.Dashboard
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want chronograf.Dashboard
|
||||
addFirst bool
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "Get Dashbaord",
|
||||
args: args{
|
||||
organization: "1337",
|
||||
ctx: context.Background(),
|
||||
dashboard: chronograf.Dashboard{
|
||||
Name: "howdy",
|
||||
Organization: "1337",
|
||||
},
|
||||
},
|
||||
want: chronograf.Dashboard{
|
||||
Name: "howdy",
|
||||
Organization: "1337",
|
||||
},
|
||||
addFirst: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
client, err := NewTestClient()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := client.Open(context.TODO()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
if tt.addFirst {
|
||||
tt.args.dashboard, _ = client.DashboardsStore.Add(tt.args.ctx, tt.args.dashboard)
|
||||
}
|
||||
s := client.OrganizationDashboardsStore
|
||||
tt.args.ctx = context.WithValue(tt.args.ctx, "organizationID", tt.args.organization)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("%q. OrganizationDashboardsStore.Add() error = %v, wantErr %v", tt.name, err, tt.wantErr)
|
||||
continue
|
||||
}
|
||||
got, err := s.Get(tt.args.ctx, tt.args.dashboard.ID)
|
||||
if diff := cmp.Diff(got, tt.want, dashboardCmpOptions...); diff != "" {
|
||||
t.Errorf("%q. OrganizationDashboardsStore.Add():\n-got/+want\ndiff %s", tt.name, diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestOrganizationDashboards_Update(t *testing.T) {
|
||||
type args struct {
|
||||
organization string
|
||||
ctx context.Context
|
||||
dashboard chronograf.Dashboard
|
||||
name string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want chronograf.Dashboard
|
||||
addFirst bool
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "Update Dashbaord Name",
|
||||
args: args{
|
||||
organization: "1337",
|
||||
ctx: context.Background(),
|
||||
dashboard: chronograf.Dashboard{
|
||||
Name: "howdy",
|
||||
Organization: "1337",
|
||||
},
|
||||
name: "doody",
|
||||
},
|
||||
want: chronograf.Dashboard{
|
||||
Name: "doody",
|
||||
Organization: "1337",
|
||||
},
|
||||
addFirst: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
client, err := NewTestClient()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := client.Open(context.TODO()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
if tt.addFirst {
|
||||
tt.args.dashboard, _ = client.DashboardsStore.Add(tt.args.ctx, tt.args.dashboard)
|
||||
}
|
||||
if tt.args.name != "" {
|
||||
tt.args.dashboard.Name = tt.args.name
|
||||
}
|
||||
s := client.OrganizationDashboardsStore
|
||||
tt.args.ctx = context.WithValue(tt.args.ctx, "organizationID", tt.args.organization)
|
||||
err = s.Update(tt.args.ctx, tt.args.dashboard)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("%q. OrganizationDashboardsStore.Update() error = %v, wantErr %v", tt.name, err, tt.wantErr)
|
||||
continue
|
||||
}
|
||||
got, err := s.Get(tt.args.ctx, tt.args.dashboard.ID)
|
||||
if diff := cmp.Diff(got, tt.want, dashboardCmpOptions...); diff != "" {
|
||||
t.Errorf("%q. OrganizationDashboardsStore.Update():\n-got/+want\ndiff %s", tt.name, diff)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue