From 0572884a4b9904da2551a1973cf425a06dd99372 Mon Sep 17 00:00:00 2001 From: Ryan Ahearn Date: Tue, 18 Jun 2024 11:56:10 -0400 Subject: [PATCH] Add redis tests with mocked provider --- .github/workflows/test.yml | 2 +- redis/tests/creation.tftest.hcl | 47 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 redis/tests/creation.tftest.hcl diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0f693db..84351b9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false max-parallel: 2 matrix: - module: ["s3", "database"] + module: ["s3", "database", "redis"] steps: - uses: actions/checkout@v4 diff --git a/redis/tests/creation.tftest.hcl b/redis/tests/creation.tftest.hcl new file mode 100644 index 0000000..d67d7b4 --- /dev/null +++ b/redis/tests/creation.tftest.hcl @@ -0,0 +1,47 @@ +mock_provider "cloudfoundry" { + mock_data "cloudfoundry_service" { + defaults = { + service_plans = { + "redis-dev" = "03c93c7b-3e1c-47c5-a6c3-1df151d280dd" + } + } + } +} + +variables { + cf_org_name = "gsa-tts-devtools-prototyping" + cf_space_name = "terraform-cloudgov-ci-tests" + redis_plan_name = "redis-dev" + name = "terraform-cloudgov-redis-test" + tags = ["terraform-cloudgov", "tests"] + json_params = jsonencode({ + engineVersion = "7.0" + }) +} + +run "test_redis_creation" { + assert { + condition = cloudfoundry_service_instance.redis.id == output.instance_id + error_message = "Instance ID output must match the service instance" + } + + assert { + condition = cloudfoundry_service_instance.redis.service_plan == data.cloudfoundry_service.redis.service_plans[var.redis_plan_name] + error_message = "Service Plan should match the redis_plan_name variable" + } + + assert { + condition = cloudfoundry_service_instance.redis.name == var.name + error_message = "Service instance name should match the name variable" + } + + assert { + condition = cloudfoundry_service_instance.redis.tags == var.tags + error_message = "Service instance tags should match the tags variable" + } + + assert { + condition = cloudfoundry_service_instance.redis.json_params == "{\"engineVersion\":\"7.0\"}" + error_message = "Service instance json_params should be configurable" + } +}