Fix group service proto for versions

This commit is contained in:
Jeff Mitchell committed 2020-08-08 19:27:49 -04:00
1 parent 4e58c55d66
commit 0c18e35b9d
7 files changed
+418 -303

No files matched your search

+28 -5
View File
@@ -8,6 +8,7 @@ import (
"github.com/hashicorp/watchtower/api"
"github.com/hashicorp/watchtower/api/groups"
"github.com/hashicorp/watchtower/api/scopes"
"github.com/hashicorp/watchtower/api/users"
"github.com/hashicorp/watchtower/internal/iam"
"github.com/hashicorp/watchtower/internal/servers/controller"
"github.com/stretchr/testify/assert"
@@ -112,7 +113,7 @@ func TestGroup_Crud(t *testing.T) {
projClient := client.Clone()
projClient.SetScopeId(proj.Id)
checkGroup := func(step string, g *groups.Group, apiErr *api.Error, err error, wantedName string) {
checkGroup := func(step string, g *groups.Group, apiErr *api.Error, err error, wantedName string, wantedVersion uint32, expectedUserIds []string) {
require.NoError(err, step)
if !assert.Nil(apiErr, step) && apiErr.Message != "" {
t.Errorf("ApiError message: %q", apiErr.Message)
@@ -123,6 +124,11 @@ func TestGroup_Crud(t *testing.T) {
gotName = g.Name
}
assert.Equal(wantedName, gotName, step)
assert.EqualValues(wantedVersion, g.Version)
assert.Equal(len(expectedUserIds), len(g.MemberIds))
if len(expectedUserIds) > 0 {
assert.EqualValues(expectedUserIds, g.MemberIds)
}
}
cases := []struct {
@@ -139,20 +145,37 @@ func TestGroup_Crud(t *testing.T) {
},
}
user1, apiErr, err := users.NewUsersClient(client).Create(tc.Context())
require.NoError(err)
require.Nil(apiErr)
user2, apiErr, err := users.NewUsersClient(client).Create(tc.Context())
require.NoError(err)
require.Nil(apiErr)
for _, tt := range cases {
t.Run(tt.name, func(t *testing.T) {
groupsClient := groups.NewGroupsClient(tt.scopeClient)
g, apiErr, err := groupsClient.Create(tc.Context(), groups.WithName("foo"))
checkGroup("create", g, apiErr, err, "foo")
checkGroup("create", g, apiErr, err, "foo", 1, nil)
g, apiErr, err = groupsClient.Read(tc.Context(), g.Id)
checkGroup("read", g, apiErr, err, "foo")
checkGroup("read", g, apiErr, err, "foo", 1, nil)
g, apiErr, err = groupsClient.Update(tc.Context(), g.Id, g.Version, groups.WithName("bar"))
checkGroup("update", g, apiErr, err, "bar")
checkGroup("update", g, apiErr, err, "bar", 2, nil)
g, apiErr, err = groupsClient.Update(tc.Context(), g.Id, g.Version, groups.DefaultName())
checkGroup("update", g, apiErr, err, "")
checkGroup("update", g, apiErr, err, "", 3, nil)
g, apiErr, err = groupsClient.AddMembers(tc.Context(), g.Id, g.Version, []string{user1.Id})
checkGroup("update", g, apiErr, err, "", 4, []string{user1.Id})
g, apiErr, err = groupsClient.SetMembers(tc.Context(), g.Id, g.Version, []string{user2.Id})
checkGroup("update", g, apiErr, err, "", 5, []string{user2.Id})
g, apiErr, err = groupsClient.RemoveMembers(tc.Context(), g.Id, g.Version, []string{user2.Id})
checkGroup("update", g, apiErr, err, "", 6, nil)
existed, apiErr, err := groupsClient.Delete(tc.Context(), g.Id)
assert.NoError(err)