diff --git a/tests/data/main.tf b/tests/data/main.tf new file mode 100644 index 00000000..4600319f --- /dev/null +++ b/tests/data/main.tf @@ -0,0 +1,11 @@ +data "opslevel_domains" "all" {} + +data "opslevel_filters" "all" {} + +data "opslevel_repositories" "all" {} + +data "opslevel_services" "all" {} + +data "opslevel_teams" "all" {} + +data "opslevel_users" "all" {} diff --git a/tests/data/outputs.tf b/tests/data/outputs.tf new file mode 100644 index 00000000..9a0dee65 --- /dev/null +++ b/tests/data/outputs.tf @@ -0,0 +1,47 @@ +output "all_domains" { + value = data.opslevel_domains.all +} + +output "all_filters" { + value = data.opslevel_filters.all +} + +output "all_repositories" { + value = data.opslevel_repositories.all +} + +output "all_services" { + value = data.opslevel_services.all +} + +output "all_teams" { + value = data.opslevel_teams.all +} + +output "all_users" { + value = data.opslevel_users.all +} + +output "first_domain" { + value = data.opslevel_domains.all.domains[0] +} + +output "first_filter" { + value = data.opslevel_filters.all.filters[0] +} + +output "first_repository" { + value = data.opslevel_repositories.all.repositories[0] +} + +output "first_service" { + value = data.opslevel_services.all.services[0] +} + +output "first_team" { + value = data.opslevel_teams.all.teams[0] +} + +output "first_user" { + value = data.opslevel_users.all.users[0] +} diff --git a/tests/data/versions.tf b/tests/data/versions.tf new file mode 120000 index 00000000..a30e1c58 --- /dev/null +++ b/tests/data/versions.tf @@ -0,0 +1 @@ +../../workspace/versions.tf \ No newline at end of file diff --git a/tests/filter_predicate_aliases.tftest.hcl b/tests/filter_predicate_aliases.tftest.hcl new file mode 100644 index 00000000..90de212a --- /dev/null +++ b/tests/filter_predicate_aliases.tftest.hcl @@ -0,0 +1,316 @@ +variables { + name = "TF Test Filter with aliases predicate" + predicate_key = "aliases" + predicate_value = "fancy" +} + +run "resource_filter_with_aliases_predicate_contains" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_contains : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_contains, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_contains, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_contains, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == var.predicate_value, + opslevel_filter.this.predicate[1].value == var.predicate_value + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + var.predicate_value, + [opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value] + ) + } + +} + +run "resource_filter_with_aliases_predicate_equals" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_equals : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_equals, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_equals, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_equals, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == var.predicate_value, + opslevel_filter.this.predicate[1].value == var.predicate_value + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + var.predicate_value, + [opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value] + ) + } + +} + +run "resource_filter_with_aliases_predicate_exists" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_exists : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = null + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_exists, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_exists, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_exists, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == null, + opslevel_filter.this.predicate[1].value == null + ]) + error_message = var.error_expected_null_field + } + +} + +run "resource_filter_with_aliases_predicate_matches_regex" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_matches_regex : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_matches_regex, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_matches_regex, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_matches_regex, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == var.predicate_value, + opslevel_filter.this.predicate[1].value == var.predicate_value + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + var.predicate_value, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + +} + +run "resource_filter_with_aliases_predicate_starts_or_ends_with" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_ends_or_starts_with : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_ends_or_starts_with, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_ends_or_starts_with, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_ends_or_starts_with, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == var.predicate_value, + opslevel_filter.this.predicate[1].value == var.predicate_value + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + var.predicate_value, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + +} diff --git a/tests/filter_predicate_domain_id.tftest.hcl b/tests/filter_predicate_domain_id.tftest.hcl new file mode 100644 index 00000000..cb339d9a --- /dev/null +++ b/tests/filter_predicate_domain_id.tftest.hcl @@ -0,0 +1,138 @@ +variables { + name = "TF Test Filter with domain_id predicate" + predicate_key = "domain_id" +} + +run "from_data_module" { + command = plan + plan_options { + target = [ + data.opslevel_domains.all + ] + } + + module { + source = "./data" + } +} + +run "resource_filter_with_domain_id_predicate_equals" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_equals : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = run.from_data_module.first_domain.id + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_equals, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_equals, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_equals, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == run.from_data_module.first_domain.id, + opslevel_filter.this.predicate[1].value == run.from_data_module.first_domain.id + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + run.from_data_module.first_domain.id, + distinct([opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value]) + ) + } + +} + +run "resource_filter_with_domain_id_predicate_exists" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_exists : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = null + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_exists, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_exists, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_exists, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == null, + opslevel_filter.this.predicate[1].value == null + ]) + error_message = var.error_expected_null_field + } +} diff --git a/tests/filter_predicate_filter_id.tftest.hcl b/tests/filter_predicate_filter_id.tftest.hcl new file mode 100644 index 00000000..ee66c6c8 --- /dev/null +++ b/tests/filter_predicate_filter_id.tftest.hcl @@ -0,0 +1,81 @@ +variables { + name = "TF Test Filter with filter_id predicate" + predicate_key = "filter_id" + predicate_types_matches = ["does_not_match", "matches"] +} + +run "from_data_module" { + command = plan + plan_options { + target = [ + data.opslevel_filters.all + ] + } + + module { + source = "./data" + } +} + +run "resource_filter_with_filter_id_predicate_matches" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_matches : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = run.from_data_module.first_filter.id + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_matches, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_matches, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_matches, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == run.from_data_module.first_filter.id, + opslevel_filter.this.predicate[1].value == run.from_data_module.first_filter.id + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + run.from_data_module.first_filter.id, + distinct([opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value]) + ) + } + +} diff --git a/tests/filter_predicate_framework.tftest.hcl b/tests/filter_predicate_framework.tftest.hcl new file mode 100644 index 00000000..25b29ae2 --- /dev/null +++ b/tests/filter_predicate_framework.tftest.hcl @@ -0,0 +1,316 @@ +variables { + name = "TF Test Filter with framework predicate" + predicate_key = "framework" + predicate_value = "fancy" +} + +run "resource_filter_with_framework_predicate_contains" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_contains : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_contains, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_contains, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_contains, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == var.predicate_value, + opslevel_filter.this.predicate[1].value == var.predicate_value + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + var.predicate_value, + [opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value] + ) + } + +} + +run "resource_filter_with_framework_predicate_equals" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_equals : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_equals, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_equals, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_equals, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == var.predicate_value, + opslevel_filter.this.predicate[1].value == var.predicate_value + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + var.predicate_value, + [opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value] + ) + } + +} + +run "resource_filter_with_framework_predicate_exists" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_exists : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = null + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_exists, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_exists, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_exists, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == null, + opslevel_filter.this.predicate[1].value == null + ]) + error_message = var.error_expected_null_field + } + +} + +run "resource_filter_with_framework_predicate_matches_regex" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_matches_regex : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_matches_regex, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_matches_regex, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_matches_regex, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == var.predicate_value, + opslevel_filter.this.predicate[1].value == var.predicate_value + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + var.predicate_value, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + +} + +run "resource_filter_with_framework_predicate_starts_or_ends_with" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_ends_or_starts_with : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_ends_or_starts_with, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_ends_or_starts_with, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_ends_or_starts_with, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == var.predicate_value, + opslevel_filter.this.predicate[1].value == var.predicate_value + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + var.predicate_value, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + +} diff --git a/tests/filter_predicate_language.tftest.hcl b/tests/filter_predicate_language.tftest.hcl new file mode 100644 index 00000000..691d217a --- /dev/null +++ b/tests/filter_predicate_language.tftest.hcl @@ -0,0 +1,317 @@ +variables { + name = "TF Test Filter with language predicate" + predicate_key = "language" + predicate_value = "fancy" +} + +run "resource_filter_with_language_predicate_contains" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_contains : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_contains, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_contains, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_contains, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == var.predicate_value, + opslevel_filter.this.predicate[1].value == var.predicate_value + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + var.predicate_value, + [opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value] + ) + } + +} + +run "resource_filter_with_language_predicate_equals" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_equals : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_equals, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_equals, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_equals, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == var.predicate_value, + opslevel_filter.this.predicate[1].value == var.predicate_value + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + var.predicate_value, + [opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value] + ) + } + +} + +run "resource_filter_with_language_predicate_exists" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_exists : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = null + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_exists, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_exists, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_exists, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == null, + opslevel_filter.this.predicate[1].value == null + ]) + error_message = var.error_expected_null_field + } + +} + +run "resource_filter_with_language_predicate_matches_regex" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_matches_regex : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_matches_regex, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_matches_regex, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_matches_regex, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == var.predicate_value, + opslevel_filter.this.predicate[1].value == var.predicate_value + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + var.predicate_value, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + +} + +run "resource_filter_with_language_predicate_starts_or_ends_with" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_ends_or_starts_with : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_ends_or_starts_with, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_ends_or_starts_with, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_ends_or_starts_with, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == var.predicate_value, + opslevel_filter.this.predicate[1].value == var.predicate_value + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + var.predicate_value, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + +} + diff --git a/tests/filter_predicate_name.tftest.hcl b/tests/filter_predicate_name.tftest.hcl new file mode 100644 index 00000000..00f8ae16 --- /dev/null +++ b/tests/filter_predicate_name.tftest.hcl @@ -0,0 +1,317 @@ +variables { + name = "TF Test Filter with name predicate" + predicate_key = "name" + predicate_value = "fancy" +} + +run "resource_filter_with_name_predicate_contains" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_contains : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_contains, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_contains, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_contains, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == var.predicate_value, + opslevel_filter.this.predicate[1].value == var.predicate_value + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + var.predicate_value, + [opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value] + ) + } + +} + +run "resource_filter_with_name_predicate_equals" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_equals : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_equals, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_equals, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_equals, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == var.predicate_value, + opslevel_filter.this.predicate[1].value == var.predicate_value + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + var.predicate_value, + [opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value] + ) + } + +} + +run "resource_filter_with_name_predicate_exists" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_exists : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = null + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_exists, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_exists, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_exists, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == null, + opslevel_filter.this.predicate[1].value == null + ]) + error_message = var.error_expected_null_field + } + +} + +run "resource_filter_with_name_predicate_matches_regex" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_matches_regex : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_matches_regex, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_matches_regex, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_matches_regex, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == var.predicate_value, + opslevel_filter.this.predicate[1].value == var.predicate_value + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + var.predicate_value, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + +} + +run "resource_filter_with_name_predicate_starts_or_ends_with" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_ends_or_starts_with : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_ends_or_starts_with, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_ends_or_starts_with, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_ends_or_starts_with, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == var.predicate_value, + opslevel_filter.this.predicate[1].value == var.predicate_value + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + var.predicate_value, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + +} + diff --git a/tests/filter_predicate_product.tftest.hcl b/tests/filter_predicate_product.tftest.hcl new file mode 100644 index 00000000..b71feff7 --- /dev/null +++ b/tests/filter_predicate_product.tftest.hcl @@ -0,0 +1,317 @@ +variables { + name = "TF Test Filter with product predicate" + predicate_key = "product" + predicate_value = "fancy" +} + +run "resource_filter_with_product_predicate_contains" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_contains : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_contains, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_contains, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_contains, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == var.predicate_value, + opslevel_filter.this.predicate[1].value == var.predicate_value + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + var.predicate_value, + [opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value] + ) + } + +} + +run "resource_filter_with_product_predicate_equals" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_equals : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_equals, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_equals, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_equals, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == var.predicate_value, + opslevel_filter.this.predicate[1].value == var.predicate_value + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + var.predicate_value, + [opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value] + ) + } + +} + +run "resource_filter_with_product_predicate_exists" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_exists : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = null + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_exists, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_exists, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_exists, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == null, + opslevel_filter.this.predicate[1].value == null + ]) + error_message = var.error_expected_null_field + } + +} + +run "resource_filter_with_product_predicate_matches_regex" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_matches_regex : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_matches_regex, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_matches_regex, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_matches_regex, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == var.predicate_value, + opslevel_filter.this.predicate[1].value == var.predicate_value + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + var.predicate_value, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + +} + +run "resource_filter_with_product_predicate_starts_or_ends_with" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_ends_or_starts_with : { + key = var.predicate_key + type = predicate_type, + key_data = null, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key == var.predicate_key, + opslevel_filter.this.predicate[1].key == var.predicate_key + ]) + error_message = format( + "expected predicate keys to all be '%v' got keys '%v'", + var.predicate_key, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + + assert { + condition = alltrue([ + contains(var.predicate_types_ends_or_starts_with, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_ends_or_starts_with, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_ends_or_starts_with, + tolist([opslevel_filter.this.predicate[0].type, opslevel_filter.this.predicate[1].type]) + ) + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].key_data == null, + opslevel_filter.this.predicate[1].key_data == null + ]) + error_message = var.error_expected_null_field + } + + assert { + condition = alltrue([ + opslevel_filter.this.predicate[0].value == var.predicate_value, + opslevel_filter.this.predicate[1].value == var.predicate_value + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + var.predicate_value, + [opslevel_filter.this.predicate[0].key, opslevel_filter.this.predicate[1].key] + ) + } + +} + diff --git a/tests/remote/filter_predicate_aliases.tftest.hcl b/tests/remote/filter_predicate_aliases.tftest.hcl deleted file mode 100644 index 7c7d464a..00000000 --- a/tests/remote/filter_predicate_aliases.tftest.hcl +++ /dev/null @@ -1,406 +0,0 @@ -variables { - name = "TF Test Filter with aliases predicate" - predicate_value = "fancy" - aliases_predicates = setproduct( - ["aliases"], - concat( - var.predicate_types_contains, - var.predicate_types_ends_or_starts_with, - var.predicate_types_matches_regex, - var.predicate_types_equals, - var.predicate_types_exists - ), - ) -} - -run "resource_filter_with_aliases_predicate_contains" { - - variables { - predicates = tomap({ - for pair in var.aliases_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if contains(var.predicate_types_contains, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["aliases_does_not_contain"].predicate[0].key == "aliases" - error_message = format( - "expected predicate key 'aliases' got '%s'", - opslevel_filter.all_predicates["aliases_does_not_contain"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_does_not_contain"].predicate[0].type == "does_not_contain" - error_message = format( - "expected predicate type 'does_not_contain' got '%s'", - opslevel_filter.all_predicates["aliases_does_not_contain"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_does_not_contain"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["aliases_does_not_contain"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["aliases_does_not_contain"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_contains"].predicate[0].key == "aliases" - error_message = format( - "expected predicate key 'aliases' got '%s'", - opslevel_filter.all_predicates["aliases_contains"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_contains"].predicate[0].type == "contains" - error_message = format( - "expected predicate type 'contains' got '%s'", - opslevel_filter.all_predicates["aliases_contains"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_contains"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["aliases_contains"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["aliases_contains"].predicate[0].value - ) - } - -} - -run "resource_filter_with_aliases_predicate_equals" { - - variables { - predicates = tomap({ - for pair in var.aliases_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if contains(var.predicate_types_equals, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["aliases_does_not_equal"].predicate[0].key == "aliases" - error_message = format( - "expected predicate key 'aliases' got '%s'", - opslevel_filter.all_predicates["aliases_does_not_equal"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_does_not_equal"].predicate[0].type == "does_not_equal" - error_message = format( - "expected predicate type 'does_not_equal' got '%s'", - opslevel_filter.all_predicates["aliases_does_not_equal"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_does_not_equal"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["aliases_does_not_equal"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["aliases_does_not_equal"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_equals"].predicate[0].key == "aliases" - error_message = format( - "expected predicate key 'aliases' got '%s'", - opslevel_filter.all_predicates["aliases_equals"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_equals"].predicate[0].type == "equals" - error_message = format( - "expected predicate type 'equals' got '%s'", - opslevel_filter.all_predicates["aliases_equals"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_equals"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["aliases_equals"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["aliases_equals"].predicate[0].value - ) - } - -} - -run "resource_filter_with_aliases_predicate_exists" { - - variables { - predicates = tomap({ - for pair in var.aliases_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = null - } - if contains(var.predicate_types_exists, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["aliases_does_not_exist"].predicate[0].key == "aliases" - error_message = format( - "expected predicate key 'aliases' got '%s'", - opslevel_filter.all_predicates["aliases_does_not_exist"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_does_not_exist"].predicate[0].type == "does_not_exist" - error_message = format( - "expected predicate type 'does_not_exist' got '%s'", - opslevel_filter.all_predicates["aliases_does_not_exist"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_does_not_exist"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["aliases_does_not_exist"].predicate[0].value == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["aliases_exists"].predicate[0].key == "aliases" - error_message = format( - "expected predicate key 'aliases' got '%s'", - opslevel_filter.all_predicates["aliases_exists"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_exists"].predicate[0].type == "exists" - error_message = format( - "expected predicate type 'exists' got '%s'", - opslevel_filter.all_predicates["aliases_exists"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_exists"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["aliases_exists"].predicate[0].value == null - error_message = var.error_expected_null_field - } - -} - -run "resource_filter_with_aliases_predicate_matches_regex" { - - variables { - predicates = tomap({ - for pair in var.aliases_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if contains(var.predicate_types_matches_regex, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["aliases_does_not_match_regex"].predicate[0].key == "aliases" - error_message = format( - "expected predicate key 'aliases' got '%s'", - opslevel_filter.all_predicates["aliases_does_not_match_regex"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_does_not_match_regex"].predicate[0].type == "does_not_match_regex" - error_message = format( - "expected predicate type 'does_not_match_regex' got '%s'", - opslevel_filter.all_predicates["aliases_does_not_match_regex"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_does_not_match_regex"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["aliases_does_not_match_regex"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["aliases_does_not_match_regex"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_matches_regex"].predicate[0].key == "aliases" - error_message = format( - "expected predicate key 'aliases' got '%s'", - opslevel_filter.all_predicates["aliases_matches_regex"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_matches_regex"].predicate[0].type == "matches_regex" - error_message = format( - "expected predicate type 'matches_regex' got '%s'", - opslevel_filter.all_predicates["aliases_matches_regex"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_matches_regex"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["aliases_matches_regex"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["aliases_matches_regex"].predicate[0].value - ) - } - -} - -run "resource_filter_with_aliases_predicate_starts_or_ends_with" { - - variables { - predicates = tomap({ - for pair in var.aliases_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if contains(var.predicate_types_ends_or_starts_with, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["aliases_ends_with"].predicate[0].key == "aliases" - error_message = format( - "expected predicate key 'aliases' got '%s'", - opslevel_filter.all_predicates["aliases_ends_with"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_ends_with"].predicate[0].type == "ends_with" - error_message = format( - "expected predicate type 'ends_with' got '%s'", - opslevel_filter.all_predicates["aliases_ends_with"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_ends_with"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["aliases_ends_with"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["aliases_ends_with"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_starts_with"].predicate[0].key == "aliases" - error_message = format( - "expected predicate key 'aliases' got '%s'", - opslevel_filter.all_predicates["aliases_starts_with"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_starts_with"].predicate[0].type == "starts_with" - error_message = format( - "expected predicate type 'starts_with' got '%s'", - opslevel_filter.all_predicates["aliases_starts_with"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["aliases_starts_with"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["aliases_starts_with"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["aliases_starts_with"].predicate[0].value - ) - } - -} diff --git a/tests/remote/filter_predicate_domain_id.tftest.hcl b/tests/remote/filter_predicate_domain_id.tftest.hcl deleted file mode 100644 index 094790e8..00000000 --- a/tests/remote/filter_predicate_domain_id.tftest.hcl +++ /dev/null @@ -1,171 +0,0 @@ -variables { - name = "TF Test Filter with domain_id predicate" - domain_id_predicates = setproduct( - ["domain_id"], - concat(var.predicate_types_equals, var.predicate_types_exists) - ) -} - -run "get_domain" { - command = plan - - variables { - name = "placeholder" - } - - module { - source = "./domain" - } -} - -run "resource_filter_with_domain_id_predicate_equals" { - - variables { - predicates = tomap({ - for pair in var.domain_id_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = run.get_domain.first_domain.id - } - if contains(var.predicate_types_equals, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["domain_id_does_not_equal"].predicate[0].key == "domain_id" - error_message = format( - "expected predicate key 'domain_id' got '%s'", - opslevel_filter.all_predicates["domain_id_does_not_equal"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["domain_id_does_not_equal"].predicate[0].type == "does_not_equal" - error_message = format( - "expected predicate type 'does_not_equal' got '%s'", - opslevel_filter.all_predicates["domain_id_does_not_equal"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["domain_id_does_not_equal"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["domain_id_does_not_equal"].predicate[0].value == run.get_domain.first_domain.id - error_message = format( - "expected predicate value '%s' got '%s'", - run.get_domain.first_domain.id, - opslevel_filter.all_predicates["domain_id_does_not_equal"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["domain_id_equals"].predicate[0].key == "domain_id" - error_message = format( - "expected predicate key 'domain_id' got '%s'", - opslevel_filter.all_predicates["domain_id_equals"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["domain_id_equals"].predicate[0].type == "equals" - error_message = format( - "expected predicate type 'equals' got '%s'", - opslevel_filter.all_predicates["domain_id_equals"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["domain_id_equals"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["domain_id_equals"].predicate[0].value == run.get_domain.first_domain.id - error_message = format( - "expected predicate value '%s' got '%s'", - run.get_domain.first_domain.id, - opslevel_filter.all_predicates["domain_id_equals"].predicate[0].type - ) - } - -} - -run "resource_filter_with_domain_id_predicate_exists" { - - variables { - predicates = tomap({ - for pair in var.domain_id_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = null - } - if contains(var.predicate_types_exists, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["domain_id_does_not_exist"].predicate[0].key == "domain_id" - error_message = format( - "expected predicate key 'domain_id' got '%s'", - opslevel_filter.all_predicates["domain_id_does_not_exist"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["domain_id_does_not_exist"].predicate[0].type == "does_not_exist" - error_message = format( - "expected predicate type 'does_not_exist' got '%s'", - opslevel_filter.all_predicates["domain_id_does_not_exist"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["domain_id_does_not_exist"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["domain_id_does_not_exist"].predicate[0].value == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["domain_id_exists"].predicate[0].key == "domain_id" - error_message = format( - "expected predicate key 'domain_id' got '%s'", - opslevel_filter.all_predicates["domain_id_exists"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["domain_id_exists"].predicate[0].type == "exists" - error_message = format( - "expected predicate type 'exists' got '%s'", - opslevel_filter.all_predicates["domain_id_exists"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["domain_id_exists"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["domain_id_exists"].predicate[0].value == null - error_message = var.error_expected_null_field - } - -} diff --git a/tests/remote/filter_predicate_filter_id.tftest.hcl b/tests/remote/filter_predicate_filter_id.tftest.hcl deleted file mode 100644 index e4df1cce..00000000 --- a/tests/remote/filter_predicate_filter_id.tftest.hcl +++ /dev/null @@ -1,95 +0,0 @@ -variables { - name = "TF Test Filter with filter_id predicate" - filter_id_predicates = setproduct(["filter_id"], ["does_not_match", "matches"]) -} - -run "get_filter" { - command = plan - - variables { - name = "placeholder" - } - - module { - source = "./filter" - } -} - -run "resource_filter_with_filter_id_predicate_matches" { - - variables { - predicates = tomap({ - for pair in var.filter_id_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = run.get_filter.first_filter.id - } - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["filter_id_does_not_match"].predicate[0].key == "filter_id" - error_message = format( - "expected predicate key 'filter_id' got '%s'", - opslevel_filter.all_predicates["filter_id_does_not_match"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["filter_id_does_not_match"].predicate[0].type == "does_not_match" - error_message = format( - "expected predicate type 'does_not_match' got '%s'", - opslevel_filter.all_predicates["filter_id_does_not_match"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["filter_id_does_not_match"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["filter_id_does_not_match"].predicate[0].value == run.get_filter.first_filter.id - error_message = format( - "expected predicate value '%s' got '%s'", - run.get_filter.first_filter.id, - opslevel_filter.all_predicates["filter_id_does_not_match"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["filter_id_matches"].predicate[0].key == "filter_id" - error_message = format( - "expected predicate key 'filter_id' got '%s'", - opslevel_filter.all_predicates["filter_id_matches"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["filter_id_matches"].predicate[0].type == "matches" - error_message = format( - "expected predicate type 'matches' got '%s'", - opslevel_filter.all_predicates["filter_id_matches"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["filter_id_matches"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["filter_id_matches"].predicate[0].value == run.get_filter.first_filter.id - error_message = format( - "expected predicate value '%s' got '%s'", - run.get_filter.first_filter.id, - opslevel_filter.all_predicates["filter_id_matches"].predicate[0].type - ) - } - -} diff --git a/tests/remote/filter_predicate_framework.tftest.hcl b/tests/remote/filter_predicate_framework.tftest.hcl deleted file mode 100644 index e02ac508..00000000 --- a/tests/remote/filter_predicate_framework.tftest.hcl +++ /dev/null @@ -1,406 +0,0 @@ -variables { - name = "TF Test Filter with framework predicate" - predicate_value = "fancy" - framework_predicates = setproduct( - ["framework"], - concat( - var.predicate_types_contains, - var.predicate_types_ends_or_starts_with, - var.predicate_types_matches_regex, - var.predicate_types_equals, - var.predicate_types_exists - ), - ) -} - -run "resource_filter_with_framework_predicate_contains" { - - variables { - predicates = tomap({ - for pair in var.framework_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if contains(var.predicate_types_contains, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["framework_does_not_contain"].predicate[0].key == "framework" - error_message = format( - "expected predicate key 'framework' got '%s'", - opslevel_filter.all_predicates["framework_does_not_contain"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_does_not_contain"].predicate[0].type == "does_not_contain" - error_message = format( - "expected predicate type 'does_not_contain' got '%s'", - opslevel_filter.all_predicates["framework_does_not_contain"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_does_not_contain"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["framework_does_not_contain"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["framework_does_not_contain"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_contains"].predicate[0].key == "framework" - error_message = format( - "expected predicate key 'framework' got '%s'", - opslevel_filter.all_predicates["framework_contains"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_contains"].predicate[0].type == "contains" - error_message = format( - "expected predicate type 'contains' got '%s'", - opslevel_filter.all_predicates["framework_contains"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_contains"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["framework_contains"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["framework_contains"].predicate[0].value - ) - } - -} - -run "resource_filter_with_framework_predicate_equals" { - - variables { - predicates = tomap({ - for pair in var.framework_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if contains(var.predicate_types_equals, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["framework_does_not_equal"].predicate[0].key == "framework" - error_message = format( - "expected predicate key 'framework' got '%s'", - opslevel_filter.all_predicates["framework_does_not_equal"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_does_not_equal"].predicate[0].type == "does_not_equal" - error_message = format( - "expected predicate type 'does_not_equal' got '%s'", - opslevel_filter.all_predicates["framework_does_not_equal"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_does_not_equal"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["framework_does_not_equal"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["framework_does_not_equal"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_equals"].predicate[0].key == "framework" - error_message = format( - "expected predicate key 'framework' got '%s'", - opslevel_filter.all_predicates["framework_equals"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_equals"].predicate[0].type == "equals" - error_message = format( - "expected predicate type 'equals' got '%s'", - opslevel_filter.all_predicates["framework_equals"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_equals"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["framework_equals"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["framework_equals"].predicate[0].value - ) - } - -} - -run "resource_filter_with_framework_predicate_exists" { - - variables { - predicates = tomap({ - for pair in var.framework_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = null - } - if contains(var.predicate_types_exists, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["framework_does_not_exist"].predicate[0].key == "framework" - error_message = format( - "expected predicate key 'framework' got '%s'", - opslevel_filter.all_predicates["framework_does_not_exist"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_does_not_exist"].predicate[0].type == "does_not_exist" - error_message = format( - "expected predicate type 'does_not_exist' got '%s'", - opslevel_filter.all_predicates["framework_does_not_exist"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_does_not_exist"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["framework_does_not_exist"].predicate[0].value == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["framework_exists"].predicate[0].key == "framework" - error_message = format( - "expected predicate key 'framework' got '%s'", - opslevel_filter.all_predicates["framework_exists"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_exists"].predicate[0].type == "exists" - error_message = format( - "expected predicate type 'exists' got '%s'", - opslevel_filter.all_predicates["framework_exists"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_exists"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["framework_exists"].predicate[0].value == null - error_message = var.error_expected_null_field - } - -} - -run "resource_filter_with_framework_predicate_matches_regex" { - - variables { - predicates = tomap({ - for pair in var.framework_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if contains(var.predicate_types_matches_regex, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["framework_does_not_match_regex"].predicate[0].key == "framework" - error_message = format( - "expected predicate key 'framework' got '%s'", - opslevel_filter.all_predicates["framework_does_not_match_regex"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_does_not_match_regex"].predicate[0].type == "does_not_match_regex" - error_message = format( - "expected predicate type 'does_not_match_regex' got '%s'", - opslevel_filter.all_predicates["framework_does_not_match_regex"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_does_not_match_regex"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["framework_does_not_match_regex"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["framework_does_not_match_regex"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_matches_regex"].predicate[0].key == "framework" - error_message = format( - "expected predicate key 'framework' got '%s'", - opslevel_filter.all_predicates["framework_matches_regex"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_matches_regex"].predicate[0].type == "matches_regex" - error_message = format( - "expected predicate type 'does_not_match_regex' got '%s'", - opslevel_filter.all_predicates["framework_matches_regex"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_matches_regex"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["framework_matches_regex"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["framework_matches_regex"].predicate[0].value - ) - } - -} - -run "resource_filter_with_framework_predicate_starts_or_ends_with" { - - variables { - predicates = tomap({ - for pair in var.framework_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if contains(var.predicate_types_ends_or_starts_with, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["framework_ends_with"].predicate[0].key == "framework" - error_message = format( - "expected predicate key 'framework' got '%s'", - opslevel_filter.all_predicates["framework_ends_with"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_ends_with"].predicate[0].type == "ends_with" - error_message = format( - "expected predicate type 'ends_with' got '%s'", - opslevel_filter.all_predicates["framework_ends_with"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_ends_with"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["framework_ends_with"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["framework_ends_with"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_starts_with"].predicate[0].key == "framework" - error_message = format( - "expected predicate key 'framework' got '%s'", - opslevel_filter.all_predicates["framework_starts_with"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_starts_with"].predicate[0].type == "starts_with" - error_message = format( - "expected predicate type 'ends_with' got '%s'", - opslevel_filter.all_predicates["framework_starts_with"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["framework_starts_with"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["framework_starts_with"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["framework_starts_with"].predicate[0].value - ) - } - -} diff --git a/tests/remote/filter_predicate_language.tftest.hcl b/tests/remote/filter_predicate_language.tftest.hcl deleted file mode 100644 index d996ea8c..00000000 --- a/tests/remote/filter_predicate_language.tftest.hcl +++ /dev/null @@ -1,406 +0,0 @@ -variables { - name = "TF Test Filter with language predicate" - predicate_value = "fancy" - language_predicates = setproduct( - ["language"], - concat( - var.predicate_types_contains, - var.predicate_types_ends_or_starts_with, - var.predicate_types_matches_regex, - var.predicate_types_equals, - var.predicate_types_exists - ), - ) -} - -run "resource_filter_with_language_predicate_contains" { - - variables { - predicates = tomap({ - for pair in var.language_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if contains(var.predicate_types_contains, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["language_does_not_contain"].predicate[0].key == "language" - error_message = format( - "expected predicate key 'language' got '%s'", - opslevel_filter.all_predicates["language_does_not_contain"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_does_not_contain"].predicate[0].type == "does_not_contain" - error_message = format( - "expected predicate type 'does_not_contain' got '%s'", - opslevel_filter.all_predicates["language_does_not_contain"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_does_not_contain"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["language_does_not_contain"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["language_does_not_contain"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_contains"].predicate[0].key == "language" - error_message = format( - "expected predicate key 'language' got '%s'", - opslevel_filter.all_predicates["language_contains"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_contains"].predicate[0].type == "contains" - error_message = format( - "expected predicate type 'contains' got '%s'", - opslevel_filter.all_predicates["language_contains"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_contains"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["language_contains"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["language_contains"].predicate[0].value - ) - } - -} - -run "resource_filter_with_language_predicate_equals" { - - variables { - predicates = tomap({ - for pair in var.language_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if contains(var.predicate_types_equals, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["language_does_not_equal"].predicate[0].key == "language" - error_message = format( - "expected predicate key 'language' got '%s'", - opslevel_filter.all_predicates["language_does_not_equal"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_does_not_equal"].predicate[0].type == "does_not_equal" - error_message = format( - "expected predicate type 'does_not_equal' got '%s'", - opslevel_filter.all_predicates["language_does_not_equal"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_does_not_equal"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["language_does_not_equal"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["language_does_not_equal"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_equals"].predicate[0].key == "language" - error_message = format( - "expected predicate key 'language' got '%s'", - opslevel_filter.all_predicates["language_equals"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_equals"].predicate[0].type == "equals" - error_message = format( - "expected predicate type 'equals' got '%s'", - opslevel_filter.all_predicates["language_equals"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_equals"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["language_equals"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["language_equals"].predicate[0].value - ) - } - -} - -run "resource_filter_with_language_predicate_exists" { - - variables { - predicates = tomap({ - for pair in var.language_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = null - } - if contains(var.predicate_types_exists, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["language_does_not_exist"].predicate[0].key == "language" - error_message = format( - "expected predicate key 'language' got '%s'", - opslevel_filter.all_predicates["language_does_not_exist"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_does_not_exist"].predicate[0].type == "does_not_exist" - error_message = format( - "expected predicate type 'does_not_exist' got '%s'", - opslevel_filter.all_predicates["language_does_not_exist"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_does_not_exist"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["language_does_not_exist"].predicate[0].value == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["language_exists"].predicate[0].key == "language" - error_message = format( - "expected predicate key 'language' got '%s'", - opslevel_filter.all_predicates["language_exists"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_exists"].predicate[0].type == "exists" - error_message = format( - "expected predicate type 'exists' got '%s'", - opslevel_filter.all_predicates["language_exists"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_exists"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["language_exists"].predicate[0].value == null - error_message = var.error_expected_null_field - } - -} - -run "resource_filter_with_language_predicate_matches_regex" { - - variables { - predicates = tomap({ - for pair in var.language_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if contains(var.predicate_types_matches_regex, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["language_does_not_match_regex"].predicate[0].key == "language" - error_message = format( - "expected predicate key 'language' got '%s'", - opslevel_filter.all_predicates["language_does_not_match_regex"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_does_not_match_regex"].predicate[0].type == "does_not_match_regex" - error_message = format( - "expected predicate type 'does_not_match_regex' got '%s'", - opslevel_filter.all_predicates["language_does_not_match_regex"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_does_not_match_regex"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["language_does_not_match_regex"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["language_does_not_match_regex"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_matches_regex"].predicate[0].key == "language" - error_message = format( - "expected predicate key 'language' got '%s'", - opslevel_filter.all_predicates["language_matches_regex"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_matches_regex"].predicate[0].type == "matches_regex" - error_message = format( - "expected predicate type 'matches_regex' got '%s'", - opslevel_filter.all_predicates["language_matches_regex"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_matches_regex"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["language_matches_regex"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["language_matches_regex"].predicate[0].value - ) - } - -} - -run "resource_filter_with_language_predicate_starts_or_ends_with" { - - variables { - predicates = tomap({ - for pair in var.language_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if contains(var.predicate_types_ends_or_starts_with, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["language_ends_with"].predicate[0].key == "language" - error_message = format( - "expected predicate key 'language' got '%s'", - opslevel_filter.all_predicates["language_ends_with"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_ends_with"].predicate[0].type == "ends_with" - error_message = format( - "expected predicate type 'ends_with' got '%s'", - opslevel_filter.all_predicates["language_ends_with"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_ends_with"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["language_ends_with"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["language_ends_with"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_starts_with"].predicate[0].key == "language" - error_message = format( - "expected predicate key 'language' got '%s'", - opslevel_filter.all_predicates["language_starts_with"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_starts_with"].predicate[0].type == "starts_with" - error_message = format( - "expected predicate type 'starts_with' got '%s'", - opslevel_filter.all_predicates["language_starts_with"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["language_starts_with"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["language_starts_with"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["language_starts_with"].predicate[0].value - ) - } - -} diff --git a/tests/remote/filter_predicate_name.tftest.hcl b/tests/remote/filter_predicate_name.tftest.hcl deleted file mode 100644 index a97970ff..00000000 --- a/tests/remote/filter_predicate_name.tftest.hcl +++ /dev/null @@ -1,406 +0,0 @@ -variables { - name = "TF Test Filter with name predicate" - predicate_value = "fancy" - name_predicates = setproduct( - ["name"], - concat( - var.predicate_types_contains, - var.predicate_types_ends_or_starts_with, - var.predicate_types_matches_regex, - var.predicate_types_equals, - var.predicate_types_exists - ), - ) -} - -run "resource_filter_with_name_predicate_contains" { - - variables { - predicates = tomap({ - for pair in var.name_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if contains(var.predicate_types_contains, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["name_does_not_contain"].predicate[0].key == "name" - error_message = format( - "expected predicate key 'name' got '%s'", - opslevel_filter.all_predicates["name_does_not_contain"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_does_not_contain"].predicate[0].type == "does_not_contain" - error_message = format( - "expected predicate type 'does_not_contain' got '%s'", - opslevel_filter.all_predicates["name_does_not_contain"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_does_not_contain"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["name_does_not_contain"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["name_does_not_contain"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_contains"].predicate[0].key == "name" - error_message = format( - "expected predicate key 'name' got '%s'", - opslevel_filter.all_predicates["name_contains"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_contains"].predicate[0].type == "contains" - error_message = format( - "expected predicate type 'contains' got '%s'", - opslevel_filter.all_predicates["name_contains"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_contains"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["name_contains"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["name_contains"].predicate[0].value - ) - } - -} - -run "resource_filter_with_name_predicate_equals" { - - variables { - predicates = tomap({ - for pair in var.name_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if contains(var.predicate_types_equals, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["name_does_not_equal"].predicate[0].key == "name" - error_message = format( - "expected predicate key 'name' got '%s'", - opslevel_filter.all_predicates["name_does_not_equal"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_does_not_equal"].predicate[0].type == "does_not_equal" - error_message = format( - "expected predicate type 'does_not_equal' got '%s'", - opslevel_filter.all_predicates["name_does_not_equal"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_does_not_equal"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["name_does_not_equal"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["name_does_not_equal"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_equals"].predicate[0].key == "name" - error_message = format( - "expected predicate key 'name' got '%s'", - opslevel_filter.all_predicates["name_equals"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_equals"].predicate[0].type == "equals" - error_message = format( - "expected predicate type 'equals' got '%s'", - opslevel_filter.all_predicates["name_equals"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_equals"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["name_equals"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["name_equals"].predicate[0].value - ) - } - -} - -run "resource_filter_with_name_predicate_exists" { - - variables { - predicates = tomap({ - for pair in var.name_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = null - } - if contains(var.predicate_types_exists, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["name_does_not_exist"].predicate[0].key == "name" - error_message = format( - "expected predicate key 'name' got '%s'", - opslevel_filter.all_predicates["name_does_not_exist"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_does_not_exist"].predicate[0].type == "does_not_exist" - error_message = format( - "expected predicate type 'does_not_exist' got '%s'", - opslevel_filter.all_predicates["name_does_not_exist"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_does_not_exist"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["name_does_not_exist"].predicate[0].value == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["name_exists"].predicate[0].key == "name" - error_message = format( - "expected predicate key 'name' got '%s'", - opslevel_filter.all_predicates["name_exists"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_exists"].predicate[0].type == "exists" - error_message = format( - "expected predicate type 'exists' got '%s'", - opslevel_filter.all_predicates["name_exists"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_exists"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["name_exists"].predicate[0].value == null - error_message = var.error_expected_null_field - } - -} - -run "resource_filter_with_name_predicate_matches_regex" { - - variables { - predicates = tomap({ - for pair in var.name_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if contains(var.predicate_types_matches_regex, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["name_does_not_match_regex"].predicate[0].key == "name" - error_message = format( - "expected predicate key 'name' got '%s'", - opslevel_filter.all_predicates["name_does_not_match_regex"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_does_not_match_regex"].predicate[0].type == "does_not_match_regex" - error_message = format( - "expected predicate type 'does_not_match_regex' got '%s'", - opslevel_filter.all_predicates["name_does_not_match_regex"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_does_not_match_regex"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["name_does_not_match_regex"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["name_does_not_match_regex"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_matches_regex"].predicate[0].key == "name" - error_message = format( - "expected predicate key 'name' got '%s'", - opslevel_filter.all_predicates["name_matches_regex"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_matches_regex"].predicate[0].type == "matches_regex" - error_message = format( - "expected predicate type 'does_not_match_regex' got '%s'", - opslevel_filter.all_predicates["name_matches_regex"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_matches_regex"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["name_matches_regex"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["name_matches_regex"].predicate[0].value - ) - } - -} - -run "resource_filter_with_name_predicate_starts_or_ends_with" { - - variables { - predicates = tomap({ - for pair in var.name_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if contains(var.predicate_types_ends_or_starts_with, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["name_ends_with"].predicate[0].key == "name" - error_message = format( - "expected predicate key 'name' got '%s'", - opslevel_filter.all_predicates["name_ends_with"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_ends_with"].predicate[0].type == "ends_with" - error_message = format( - "expected predicate type 'ends_with' got '%s'", - opslevel_filter.all_predicates["name_ends_with"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_ends_with"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["name_ends_with"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["name_ends_with"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_starts_with"].predicate[0].key == "name" - error_message = format( - "expected predicate key 'name' got '%s'", - opslevel_filter.all_predicates["name_starts_with"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_starts_with"].predicate[0].type == "starts_with" - error_message = format( - "expected predicate type 'ends_with' got '%s'", - opslevel_filter.all_predicates["name_starts_with"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["name_starts_with"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["name_starts_with"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["name_starts_with"].predicate[0].value - ) - } - -} diff --git a/tests/remote/filter_predicate_product.tftest.hcl b/tests/remote/filter_predicate_product.tftest.hcl deleted file mode 100644 index 9f6f87f9..00000000 --- a/tests/remote/filter_predicate_product.tftest.hcl +++ /dev/null @@ -1,406 +0,0 @@ -variables { - name = "TF Test Filter with product predicate" - predicate_value = "fancy" - product_predicates = setproduct( - ["product"], - concat( - var.predicate_types_contains, - var.predicate_types_ends_or_starts_with, - var.predicate_types_matches_regex, - var.predicate_types_equals, - var.predicate_types_exists - ), - ) -} - -run "resource_filter_with_product_predicate_contains" { - - variables { - predicates = tomap({ - for pair in var.product_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if contains(var.predicate_types_contains, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["product_does_not_contain"].predicate[0].key == "product" - error_message = format( - "expected predicate key 'product' got '%s'", - opslevel_filter.all_predicates["product_does_not_contain"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_does_not_contain"].predicate[0].type == "does_not_contain" - error_message = format( - "expected predicate type 'does_not_contain' got '%s'", - opslevel_filter.all_predicates["product_does_not_contain"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_does_not_contain"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["product_does_not_contain"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["product_does_not_contain"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_contains"].predicate[0].key == "product" - error_message = format( - "expected predicate key 'product' got '%s'", - opslevel_filter.all_predicates["product_contains"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_contains"].predicate[0].type == "contains" - error_message = format( - "expected predicate type 'contains' got '%s'", - opslevel_filter.all_predicates["product_contains"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_contains"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["product_contains"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["product_contains"].predicate[0].value - ) - } - -} - -run "resource_filter_with_product_predicate_equals" { - - variables { - predicates = tomap({ - for pair in var.product_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if contains(var.predicate_types_equals, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["product_does_not_equal"].predicate[0].key == "product" - error_message = format( - "expected predicate key 'product' got '%s'", - opslevel_filter.all_predicates["product_does_not_equal"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_does_not_equal"].predicate[0].type == "does_not_equal" - error_message = format( - "expected predicate type 'does_not_equal' got '%s'", - opslevel_filter.all_predicates["product_does_not_equal"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_does_not_equal"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["product_does_not_equal"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["product_does_not_equal"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_equals"].predicate[0].key == "product" - error_message = format( - "expected predicate key 'product' got '%s'", - opslevel_filter.all_predicates["product_equals"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_equals"].predicate[0].type == "equals" - error_message = format( - "expected predicate type 'equals' got '%s'", - opslevel_filter.all_predicates["product_equals"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_equals"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["product_equals"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["product_equals"].predicate[0].value - ) - } - -} - -run "resource_filter_with_product_predicate_exists" { - - variables { - predicates = tomap({ - for pair in var.product_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = null - } - if contains(var.predicate_types_exists, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["product_does_not_exist"].predicate[0].key == "product" - error_message = format( - "expected predicate key 'product' got '%s'", - opslevel_filter.all_predicates["product_does_not_exist"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_does_not_exist"].predicate[0].type == "does_not_exist" - error_message = format( - "expected predicate type 'does_not_exist' got '%s'", - opslevel_filter.all_predicates["product_does_not_exist"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_does_not_exist"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["product_does_not_exist"].predicate[0].value == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["product_exists"].predicate[0].key == "product" - error_message = format( - "expected predicate key 'product' got '%s'", - opslevel_filter.all_predicates["product_exists"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_exists"].predicate[0].type == "exists" - error_message = format( - "expected predicate type 'exists' got '%s'", - opslevel_filter.all_predicates["product_exists"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_exists"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["product_exists"].predicate[0].value == null - error_message = var.error_expected_null_field - } - -} - -run "resource_filter_with_product_predicate_matches_regex" { - - variables { - predicates = tomap({ - for pair in var.product_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if contains(var.predicate_types_matches_regex, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["product_does_not_match_regex"].predicate[0].key == "product" - error_message = format( - "expected predicate key 'product' got '%s'", - opslevel_filter.all_predicates["product_does_not_match_regex"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_does_not_match_regex"].predicate[0].type == "does_not_match_regex" - error_message = format( - "expected predicate type 'does_not_match_regex' got '%s'", - opslevel_filter.all_predicates["product_does_not_match_regex"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_does_not_match_regex"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["product_does_not_match_regex"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["product_does_not_match_regex"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_matches_regex"].predicate[0].key == "product" - error_message = format( - "expected predicate key 'product' got '%s'", - opslevel_filter.all_predicates["product_matches_regex"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_matches_regex"].predicate[0].type == "matches_regex" - error_message = format( - "expected predicate type 'matches_regex' got '%s'", - opslevel_filter.all_predicates["product_matches_regex"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_matches_regex"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["product_matches_regex"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["product_matches_regex"].predicate[0].value - ) - } - -} - -run "resource_filter_with_product_predicate_starts_or_ends_with" { - - variables { - predicates = tomap({ - for pair in var.product_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if contains(var.predicate_types_ends_or_starts_with, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["product_ends_with"].predicate[0].key == "product" - error_message = format( - "expected predicate key 'product' got '%s'", - opslevel_filter.all_predicates["product_ends_with"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_ends_with"].predicate[0].type == "ends_with" - error_message = format( - "expected predicate type 'ends_with' got '%s'", - opslevel_filter.all_predicates["product_ends_with"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_ends_with"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["product_ends_with"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["product_ends_with"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_starts_with"].predicate[0].key == "product" - error_message = format( - "expected predicate key 'product' got '%s'", - opslevel_filter.all_predicates["product_starts_with"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_starts_with"].predicate[0].type == "starts_with" - error_message = format( - "expected predicate type 'starts_with' got '%s'", - opslevel_filter.all_predicates["product_starts_with"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["product_starts_with"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["product_starts_with"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["product_starts_with"].predicate[0].value - ) - } - -}