Skip to content

Commit 985e154

Browse files
committed
test: implement new test structure for disabled, minimum and complete tests
1 parent b0b52ea commit 985e154

File tree

13 files changed

+1231
-357
lines changed

13 files changed

+1231
-357
lines changed

go.mod

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
1-
module github.com/mineiros/terraform-aws-cognito-user-pool
1+
module github.com/mineiros-io/terraform-aws-cognito-user-pool
22

3-
go 1.14
3+
go 1.17
44

5-
require github.com/gruntwork-io/terratest v0.30.0
5+
require (
6+
github.com/gruntwork-io/terratest v0.38.2
7+
github.com/stretchr/testify v1.7.0
8+
)
9+
10+
require (
11+
github.com/agext/levenshtein v1.2.3 // indirect
12+
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
13+
github.com/davecgh/go-spew v1.1.1 // indirect
14+
github.com/hashicorp/errwrap v1.0.0 // indirect
15+
github.com/hashicorp/go-multierror v1.1.0 // indirect
16+
github.com/hashicorp/hcl/v2 v2.9.1 // indirect
17+
github.com/hashicorp/terraform-json v0.12.0 // indirect
18+
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect
19+
github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 // indirect
20+
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
21+
github.com/pmezard/go-difflib v1.0.0 // indirect
22+
github.com/tmccombs/hcl2json v0.3.3 // indirect
23+
github.com/zclconf/go-cty v1.8.1 // indirect
24+
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
25+
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
26+
golang.org/x/sys v0.0.0-20210603125802-9665404d3644 // indirect
27+
golang.org/x/text v0.3.6 // indirect
28+
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
29+
)

go.sum

Lines changed: 846 additions & 159 deletions
Large diffs are not rendered by default.

test/README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ of the modules that ship with this repository.
1212
## Introduction
1313

1414
We are using [Terratest] for automated tests that are located in the
15-
[`test/` directory][Testdirectory]. Terratest deploys _real_ infrastructure
15+
[`test/` directory][testdirectory]. Terratest deploys _real_ infrastructure
1616
(e.g., servers) in a _real_ environment (e.g., AWS).
1717

1818
The basic usage pattern for writing automated tests with Terratest is to:
@@ -58,25 +58,27 @@ Alternatively, you can also run the tests without Docker.
5858
3. Set your AWS credentials as environment variables: `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`
5959
4. Install go dependencies: `go mod download`
6060
5. Run all tests: `go test -v -count 1 -timeout 45m -parallel 128 ./test/...`
61+
or use the convenient `make test/unit-tests` Makefile target.
6162
6. Run a specific test: `go test -count 1 -v -timeout 45m -parallel 128 test/example_test.go`
6263

6364
<!-- References -->
6465

6566
<!-- markdown-link-check-disable -->
66-
[Makefile]: https://github.com/mineiros-io/terraform-aws-cognito-user-pool/blob/master/Makefile
67-
[Testdirectory]: https://github.com/mineiros-io/terraform-aws-cognito-user-pool/tree/master/test
67+
68+
[makefile]: https://github.com/mineiros-io/terraform-aws-cognito-user-pool/blob/main/Makefile
69+
[testdirectory]: https://github.com/mineiros-io/terraform-aws-cognito-user-pool/tree/main/test
70+
6871
<!-- markdown-link-check-enable -->
6972

7073
[homepage]: https://mineiros.io/?ref=terraform-aws-cognito-user-pool
71-
[Terratest]: https://github.com/gruntwork-io/terratest
74+
[terratest]: https://github.com/gruntwork-io/terratest
7275
[package testing]: https://golang.org/pkg/testing/
73-
[Docker]: https://docs.docker.com/get-started/
74-
[Go]: https://golang.org/
75-
[Terraform]: https://www.terraform.io/downloads.html
76+
[docker]: https://docs.docker.com/get-started/
77+
[go]: https://golang.org/
78+
[terraform]: https://www.terraform.io/downloads.html
7679
[badge-license]: https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg
7780
[badge-terraform]: https://img.shields.io/badge/terraform-1.x%20|%200.15%20|%200.14%20|%200.13%20|%200.12.20+-623CE4.svg?logo=terraform
7881
[badge-slack]: https://img.shields.io/badge/[email protected]?logo=slack
79-
8082
[releases-terraform]: https://github.com/hashicorp/terraform/releases
8183
[apache20]: https://opensource.org/licenses/Apache-2.0
82-
[slack]: https://join.slack.com/t/mineiros-community/shared_invite/zt-ehidestg-aLGoIENLVs6tvwJ11w9WGg
84+
[slack]: https://mineiros.io/slack

test/terraform_aws_cognito_user_pool_test.go

Lines changed: 0 additions & 50 deletions
This file was deleted.

test/unit-complete/main.tf

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
# COMPLETE FEATURES UNIT TEST
3+
# This module tests a complete set of most/all non-exclusive features
4+
# The purpose is to activate everything the module offers, but trying to keep execution time and costs minimal.
5+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6+
7+
variable "aws_region" {
8+
description = "(Optional) The AWS region in which all resources will be created."
9+
type = string
10+
default = "us-east-1"
11+
}
12+
13+
terraform {
14+
required_providers {
15+
aws = {
16+
source = "hashicorp/aws"
17+
version = "~> 3.50"
18+
}
19+
}
20+
}
21+
22+
provider "aws" {
23+
region = var.aws_region
24+
}
25+
26+
# DO NOT RENAME MODULE NAME
27+
module "test" {
28+
source = "../.."
29+
30+
module_enabled = true
31+
32+
# add all required arguments
33+
name = "example-cognito-user-pool"
34+
35+
# add all optional arguments that create additional resources
36+
clients = [
37+
{
38+
name = "android-mobile-client"
39+
read_attributes = ["email", "email_verified", "preferred_username"]
40+
allowed_oauth_scopes = ["email", "openid"]
41+
allowed_oauth_flows = ["implicit"]
42+
callback_urls = ["https://mineiros.io/callback", "https://mineiros.io/anothercallback"]
43+
default_redirect_uri = "https://mineiros.io/callback"
44+
generate_secret = true
45+
}
46+
]
47+
48+
# add most/all other optional arguments
49+
50+
enable_username_case_sensitivity = false
51+
advanced_security_mode = "ENFORCED"
52+
53+
alias_attributes = [
54+
"email",
55+
"phone_number",
56+
"preferred_username",
57+
]
58+
59+
auto_verified_attributes = [
60+
"email"
61+
]
62+
63+
account_recovery_mechanisms = [
64+
{
65+
name = "verified_email"
66+
priority = 1
67+
},
68+
{
69+
name = "verified_phone_number"
70+
priority = 2
71+
}
72+
]
73+
74+
# If invited by an admin
75+
invite_email_subject = "You've been invited to Mineiros.io"
76+
invite_email_message = "Hi {username}, your temporary password is '{####}'."
77+
invite_sms_message = "Hi {username}, your temporary password is '{####}'."
78+
79+
# domain = "mineiros-dev"
80+
default_email_option = "CONFIRM_WITH_LINK"
81+
email_subject_by_link = "Your Verification Link"
82+
email_message_by_link = "Please click the link below to verify your email address. {##Verify Email##}."
83+
sms_message = "Your verification code is {####}."
84+
85+
challenge_required_on_new_device = true
86+
user_device_tracking = "USER_OPT_IN"
87+
88+
# These paramters can be used to configure SES for emails
89+
# email_sending_account = "DEVELOPER"
90+
# email_reply_to_address = "[email protected]"
91+
# email_from_address = "[email protected]"
92+
# email_source_arn = "arn:aws:ses:us-east-1:999999999999:identity"
93+
94+
# Require MFA
95+
mfa_configuration = "ON"
96+
allow_software_mfa_token = true
97+
98+
password_minimum_length = 40
99+
password_require_lowercase = true
100+
password_require_numbers = true
101+
password_require_uppercase = true
102+
password_require_symbols = true
103+
104+
temporary_password_validity_days = 3
105+
106+
schema_attributes = [
107+
{
108+
name = "gender", # overwrites the default attribute 'gender'
109+
type = "String"
110+
required = true
111+
min_length = 1
112+
max_length = 2048
113+
},
114+
{
115+
name = "alternative_name"
116+
type = "String"
117+
developer_only_attribute = false,
118+
mutable = true,
119+
required = false,
120+
min_length = 0,
121+
max_length = 2048
122+
},
123+
{
124+
name = "friends_count"
125+
type = "Number"
126+
min_value = 0,
127+
max_value = 100
128+
},
129+
{
130+
name = "is_active"
131+
type = "Boolean"
132+
133+
},
134+
{
135+
name = "last_seen"
136+
type = "DateTime"
137+
}
138+
]
139+
140+
default_client_token_validity_units = {
141+
refresh_token = "hours"
142+
access_token = "hours"
143+
id_token = "hours"
144+
}
145+
146+
tags = {
147+
Team = "Unknown"
148+
}
149+
150+
module_tags = {
151+
Environment = "unknown"
152+
}
153+
154+
module_depends_on = ["nothing"]
155+
}
156+
157+
# outputs generate non-idempotent terraform plans so we disable them for now unless we need them.
158+
# output "all" {
159+
# description = "All outputs of the module."
160+
# value = module.test
161+
# }

test/unit-disabled/main.tf

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
# EMPTY FEATURES (DISABLED) UNIT TEST
3+
# This module tests an empty set of features.
4+
# The purpose is to verify no resources are created when the module is disabled.
5+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6+
7+
variable "aws_region" {
8+
description = "(Optional) The AWS region in which all resources will be created."
9+
type = string
10+
default = "us-east-1"
11+
}
12+
13+
terraform {
14+
required_providers {
15+
aws = {
16+
source = "hashicorp/aws"
17+
version = "~> 3.50"
18+
}
19+
}
20+
}
21+
22+
provider "aws" {
23+
region = var.aws_region
24+
}
25+
26+
# DO NOT RENAME MODULE NAME
27+
module "test" {
28+
source = "../.."
29+
30+
name = "example-cognito-user-pool"
31+
32+
module_enabled = false
33+
34+
# add all required arguments
35+
36+
# add all optional arguments that create additional resources
37+
}
38+
39+
# outputs generate non-idempotent terraform plans so we disable them for now unless we need them.
40+
# output "all" {
41+
# description = "All outputs of the module."
42+
# value = module.test
43+
# }

test/unit-minimal/main.tf

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
# MINIMAL FEATURES UNIT TEST
3+
# This module tests a minimal set of features.
4+
# The purpose is to test all defaults for optional arguments and just provide the required arguments.
5+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6+
7+
variable "aws_region" {
8+
description = "(Optional) The AWS region in which all resources will be created."
9+
type = string
10+
default = "us-east-1"
11+
}
12+
13+
terraform {
14+
required_providers {
15+
aws = {
16+
source = "hashicorp/aws"
17+
# always test with exact version to catch unsupported blocks/arguments early
18+
# this should match the minimal version in versions.tf
19+
version = "3.50.0"
20+
}
21+
}
22+
}
23+
24+
provider "aws" {
25+
region = var.aws_region
26+
}
27+
28+
# DO NOT RENAME MODULE NAME
29+
module "test" {
30+
source = "../.."
31+
32+
name = "example-cognito-user-pool"
33+
34+
# add only required arguments and no optional arguments
35+
}
36+
37+
# outputs generate non-idempotent terraform plans so we disable them for now unless we need them.
38+
# output "all" {
39+
# description = "All outputs of the module."
40+
# value = module.test
41+
# }

0 commit comments

Comments
 (0)