Improve get no users test

Change rawWant to wantRaw
Remove fmt.Println

Signed-off-by: Michael de Sa <mjdesa@gmail.com>
pull/10616/head
Jared Scheib 2017-10-24 13:33:17 -07:00 committed by Michael de Sa
parent 0aa28d7066
commit 18054c6645
1 changed files with 46 additions and 9 deletions

View File

@ -2,7 +2,6 @@ package bolt_test
import ( import (
"context" "context"
"fmt"
"testing" "testing"
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
@ -228,6 +227,7 @@ func TestOrganizationUsersStore_Add(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
defer client.Close() defer client.Close()
tt.args.ctx = context.WithValue(tt.args.ctx, "organizationID", tt.args.orgID) tt.args.ctx = context.WithValue(tt.args.ctx, "organizationID", tt.args.orgID)
s := client.OrganizationUsersStore s := client.OrganizationUsersStore
got, err := s.Add(tt.args.ctx, tt.args.u) got, err := s.Add(tt.args.ctx, tt.args.u)
@ -467,7 +467,7 @@ func TestOrganizationUsersStore_All(t *testing.T) {
name string name string
ctx context.Context ctx context.Context
want []chronograf.User want []chronograf.User
rawWant []chronograf.User wantRaw []chronograf.User
orgID string orgID string
addFirst bool addFirst bool
wantErr bool wantErr bool
@ -475,6 +475,46 @@ func TestOrganizationUsersStore_All(t *testing.T) {
{ {
name: "No users", name: "No users",
ctx: context.Background(), ctx: context.Background(),
wantRaw: []chronograf.User{
{
Name: "howdy",
Provider: "GitHub",
Scheme: "OAuth2",
Roles: []chronograf.Role{
{
OrganizationID: "1338",
Name: "Viewer",
},
{
OrganizationID: "1336",
Name: "Viewer",
},
},
},
{
Name: "doody2",
Provider: "GitHub2",
Scheme: "OAuth2",
Roles: []chronograf.Role{
{
OrganizationID: "1337",
Name: "Editor",
},
},
},
{
Name: "doody",
Provider: "GitHub",
Scheme: "OAuth2",
Roles: []chronograf.Role{
{
OrganizationID: "1338",
Name: "Editor",
},
},
},
},
orgID: "2330",
}, },
{ {
name: "get all users", name: "get all users",
@ -504,7 +544,7 @@ func TestOrganizationUsersStore_All(t *testing.T) {
}, },
}, },
}, },
rawWant: []chronograf.User{ wantRaw: []chronograf.User{
{ {
Name: "howdy", Name: "howdy",
Provider: "GitHub", Provider: "GitHub",
@ -558,21 +598,18 @@ func TestOrganizationUsersStore_All(t *testing.T) {
tt.ctx = context.WithValue(tt.ctx, "organizationID", tt.orgID) tt.ctx = context.WithValue(tt.ctx, "organizationID", tt.orgID)
if tt.addFirst { if tt.addFirst {
for _, u := range tt.rawWant { for _, u := range tt.wantRaw {
client.UsersStore.Add(tt.ctx, &u) client.UsersStore.Add(tt.ctx, &u)
} }
} }
s := client.OrganizationUsersStore s := client.OrganizationUsersStore
fmt.Println(tt.name)
gots, err := s.All(tt.ctx) gots, err := s.All(tt.ctx)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("%q. OrganizationUsersStore.All() error = %v, wantErr %v", tt.name, err, tt.wantErr) t.Errorf("%q. OrganizationUsersStore.All() error = %v, wantErr %v", tt.name, err, tt.wantErr)
continue continue
} }
for i, got := range gots { if diff := cmp.Diff(gots, tt.want, cmpOptions...); diff != "" {
if diff := cmp.Diff(got, tt.want[i], cmpOptions...); diff != "" { t.Errorf("%q. OrganizationUsersStore.All():\n-got/+want\ndiff %s", tt.name, diff)
t.Errorf("%q. OrganizationUsersStore.All():\n-got/+want\ndiff %s", tt.name, diff)
}
} }
} }
} }