Skip to content

Commit 75f030f

Browse files
chore: add groups to integration test (#34)
1 parent 17513d7 commit 75f030f

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

integration/integration_test.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestIntegration(t *testing.T) {
5050
preF: func(t testing.TB, c *codersdk.Client) {
5151
me, err := c.User(ctx, codersdk.Me)
5252
assert.NoError(t, err)
53-
_, err = c.CreateUser(ctx, codersdk.CreateUserRequest{
53+
user1, err := c.CreateUser(ctx, codersdk.CreateUserRequest{
5454
Email: "test2@coder.com",
5555
Username: "ethan",
5656
Password: "SomeSecurePassword!",
@@ -59,6 +59,15 @@ func TestIntegration(t *testing.T) {
5959
OrganizationID: me.OrganizationIDs[0],
6060
})
6161
assert.NoError(t, err)
62+
group, err := c.CreateGroup(ctx, me.OrganizationIDs[0], codersdk.CreateGroupRequest{
63+
Name: "bosses",
64+
QuotaAllowance: 200,
65+
})
66+
assert.NoError(t, err)
67+
_, err = c.PatchGroup(ctx, group.ID, codersdk.PatchGroupRequest{
68+
AddUsers: []string{user1.ID.String()},
69+
})
70+
assert.NoError(t, err)
6271
},
6372
assertF: func(t testing.TB, c *codersdk.Client) {
6473
// Check user fields.
@@ -86,6 +95,14 @@ func TestIntegration(t *testing.T) {
8695
user, err = newClient.User(ctx, codersdk.Me)
8796
assert.NoError(t, err)
8897
assert.Equal(t, "dean", user.Username)
98+
99+
// Check group
100+
defaultOrg, err := c.OrganizationByName(ctx, "first-organization")
101+
assert.NoError(t, err)
102+
group, err := c.GroupByOrgAndName(ctx, defaultOrg.ID, "employees")
103+
assert.NoError(t, err)
104+
assert.Len(t, group.Members, 3)
105+
assert.Equal(t, group.QuotaAllowance, 100)
89106
},
90107
},
91108
} {
@@ -112,6 +129,7 @@ func TestIntegration(t *testing.T) {
112129
tt.preF(t, client)
113130
if err := tfCmd.Run(); !assert.NoError(t, err) {
114131
t.Logf(buf.String())
132+
t.FailNow()
115133
}
116134
tt.assertF(t, client)
117135
})

integration/user-test/main.tf

+23
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,26 @@ resource "coderd_user" "ethan2" {
2828
roles = data.coderd_user.ethan.roles
2929
suspended = data.coderd_user.ethan.suspended
3030
}
31+
32+
data "coderd_organization" "default" {
33+
is_default = true
34+
}
35+
36+
data "coderd_group" "bosses" {
37+
name = "bosses"
38+
organization_id = data.coderd_organization.default.id
39+
}
40+
41+
resource "coderd_group" "employees" {
42+
name = "employees"
43+
organization_id = data.coderd_organization.default.id
44+
quota_allowance = 100
45+
members = concat([
46+
resource.coderd_user.dean.id,
47+
resource.coderd_user.ethan2.id,
48+
], data.coderd_group.bosses.members[*].id)
49+
}
50+
51+
data "coderd_group" "employees" {
52+
id = resource.coderd_group.employees.id
53+
}

0 commit comments

Comments
 (0)