test(targets): Change test to not depend on response order (#1653)

This test started failing when the order of the list response changed.
Since the order does not matter, this test was updated to not depend on
the order.
pull/1660/head
Timothy Messier 4 years ago committed by GitHub
parent f53772519c
commit decc3ec2cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -288,7 +288,16 @@ func TestList(t *testing.T) {
return
}
require.NoError(gErr)
assert.Empty(cmp.Diff(got, tc.res, protocmp.Transform()), "ListTargets(%q) scope %q, got response %q, wanted %q", tc.name, tc.req.GetScopeId(), got, tc.res)
assert.Equal(len(tc.res.Items), len(got.Items))
wantById := make(map[string]*pb.Target, len(tc.res.Items))
for _, t := range tc.res.Items {
wantById[t.Id] = t
}
for _, t := range got.Items {
want, ok := wantById[t.Id]
assert.True(ok, "Got unexpected target with id: %s", t.Id)
assert.Empty(cmp.Diff(t, want, protocmp.Transform()), "got %v, wanted %v", t, want)
}
// Test with anon user
got, gErr = s.ListTargets(auth.DisabledAuthTestContext(iamRepoFn, tc.req.GetScopeId(), auth.WithUserId(auth.AnonymousUserId)), tc.req)

Loading…
Cancel
Save