Skip to content

Commit

Permalink
chore: add groups to integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanndickson committed Jul 22, 2024
1 parent aa86273 commit cae8c17
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
20 changes: 19 additions & 1 deletion integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestIntegration(t *testing.T) {
preF: func(t testing.TB, c *codersdk.Client) {
me, err := c.User(ctx, codersdk.Me)
assert.NoError(t, err)
_, err = c.CreateUser(ctx, codersdk.CreateUserRequest{
user1, err := c.CreateUser(ctx, codersdk.CreateUserRequest{
Email: "[email protected]",
Username: "ethan",
Password: "SomeSecurePassword!",
Expand All @@ -59,6 +59,15 @@ func TestIntegration(t *testing.T) {
OrganizationID: me.OrganizationIDs[0],
})
assert.NoError(t, err)
group, err := c.CreateGroup(ctx, me.OrganizationIDs[0], codersdk.CreateGroupRequest{
Name: "bosses",
QuotaAllowance: 200,
})
assert.NoError(t, err)
_, err = c.PatchGroup(ctx, group.ID, codersdk.PatchGroupRequest{
AddUsers: []string{user1.ID.String()},
})
assert.NoError(t, err)
},
assertF: func(t testing.TB, c *codersdk.Client) {
// Check user fields.
Expand Down Expand Up @@ -86,6 +95,14 @@ func TestIntegration(t *testing.T) {
user, err = newClient.User(ctx, codersdk.Me)
assert.NoError(t, err)
assert.Equal(t, "dean", user.Username)

// Check group
defaultOrg, err := c.OrganizationByName(ctx, "first-organization")
assert.NoError(t, err)
group, err := c.GroupByOrgAndName(ctx, defaultOrg.ID, "employees")
assert.NoError(t, err)
assert.Len(t, group.Members, 3)
assert.Equal(t, group.QuotaAllowance, 100)
},
},
} {
Expand All @@ -112,6 +129,7 @@ func TestIntegration(t *testing.T) {
tt.preF(t, client)
if err := tfCmd.Run(); !assert.NoError(t, err) {
t.Logf(buf.String())
t.FailNow()
}
tt.assertF(t, client)
})
Expand Down
23 changes: 23 additions & 0 deletions integration/user-test/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,26 @@ resource "coderd_user" "ethan2" {
roles = data.coderd_user.ethan.roles
suspended = data.coderd_user.ethan.suspended
}

data "coderd_organization" "default" {
is_default = true
}

data "coderd_group" "bosses" {
name = "bosses"
organization_id = data.coderd_organization.default.id
}

resource "coderd_group" "employees" {
name = "employees"
organization_id = data.coderd_organization.default.id
quota_allowance = 100
members = concat([
resource.coderd_user.dean.id,
resource.coderd_user.ethan2.id,
], data.coderd_group.bosses.members[*].id)
}

data "coderd_group" "employees" {
id = resource.coderd_group.employees.id
}

0 comments on commit cae8c17

Please sign in to comment.