Skip to content

Commit 933242a

Browse files
feat: revised tests while writing article about the tests we added in this module (#15)
## what - I previously wrote some vauge tests in the repo and am updating them to test things (I think) better. - add assertions in tests - testing for just success is less helpful - removed un-useful data in `group_member_type_invalid`
1 parent 9b9112a commit 933242a

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ backend.tf.json
4646
**/.DS_Store
4747

4848
.cursor/rules
49+
.claude

tests/variables_groups.tftest.hcl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ run "email_success" {
2121
}
2222
}
2323
}
24+
25+
assert {
26+
condition = googleworkspace_group.defaults["team1@example.com"].name == "Team 1"
27+
error_message = "Expected 'name' to be 'Team 1'."
28+
}
2429
}
2530

2631
run "email_invalid_missing_domain" {
@@ -67,6 +72,11 @@ run "group_settings_specific_values" {
6772
}
6873
}
6974
# We expect this plan to succeed as the structure is valid.
75+
76+
assert {
77+
condition = googleworkspace_group_settings.defaults["settings-test-group@example.com"].who_can_join == "INVITED_CAN_JOIN"
78+
error_message = "Expected 'who_can_join' to be 'INVITED_CAN_JOIN'."
79+
}
7080
}
7181

7282
run "group_settings_no_settings_block" {
@@ -86,4 +96,9 @@ run "group_settings_no_settings_block" {
8696
}
8797
}
8898
# We expect this plan to succeed.
99+
100+
assert {
101+
condition = googleworkspace_group.defaults["no-settings-test-group@example.com"].name == "No Settings Test Group"
102+
error_message = "Expected 'name' to be 'No Settings Test Group'."
103+
}
89104
}

tests/variables_users.tftest.hcl

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ run "email_success" {
2222
}
2323
}
2424
}
25+
26+
assert {
27+
condition = googleworkspace_user.defaults["first.last@example.com"].primary_email == "first.last@example.com"
28+
error_message = "Expected 'primary_email' to be 'first.last@example.com'."
29+
}
2530
}
2631

2732
run "email_invalid_missing_at_symbol" {
@@ -63,10 +68,12 @@ run "password_success" {
6368
family_name = "Last"
6469
given_name = "First"
6570
password = "password"
66-
hash_function = "MD5"
6771
}
6872
}
6973
}
74+
75+
# pasword is a write only field, so don't test the output
76+
expect_failures = []
7077
}
7178

7279
run "password_too_short" {
@@ -135,6 +142,11 @@ run "hash_function_md5_success" {
135142
}
136143
}
137144
}
145+
146+
assert {
147+
condition = googleworkspace_user.defaults["first.last@example.com"].hash_function == "MD5"
148+
error_message = "Expected 'hash_function' to be 'MD5'."
149+
}
138150
}
139151

140152
run "hash_function_invalid" {
@@ -281,7 +293,7 @@ run "custom_schemas_output_verification" {
281293
# -----------------------------------------------------------------------------
282294

283295
run "groups_member_role_success" {
284-
command = plan
296+
command = apply
285297

286298
providers = {
287299
googleworkspace = googleworkspace.mock
@@ -307,6 +319,11 @@ run "groups_member_role_success" {
307319
}
308320
}
309321
}
322+
323+
assert {
324+
condition = googleworkspace_group_member.user_to_groups["team@example.com/first.last@example.com"].role == "MEMBER"
325+
error_message = "Expected 'role' to be 'MEMBER'."
326+
}
310327
}
311328

312329
run "groups_member_role_invalid" {
@@ -460,7 +477,6 @@ run "group_member_type_invalid" {
460477
given_name = "Invalid"
461478
groups = {
462479
"test-group" = {
463-
role = "MEMBER"
464480
type = "INVALID-TYPE"
465481
}
466482
}

variables.tf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ variable "users" {
104104
condition = alltrue(flatten([
105105
for user in var.users : [
106106
for group in values(try(user.groups, {})) : (
107-
# # Check if type is null (default) or one of the allowed values
108-
# group.type == null ? true : (upper(group.type) == "USER" || upper(group.type) == "GROUP" || upper(group.type) == "CUSTOMER")
109107
group.type == null || contains(["USER", "GROUP", "CUSTOMER"], upper(group.type))
110108
)
111109
]

0 commit comments

Comments
 (0)