diff --git a/tests/data/main.tf b/tests/data/main.tf index 4600319f..1d1922e0 100644 --- a/tests/data/main.tf +++ b/tests/data/main.tf @@ -6,6 +6,8 @@ data "opslevel_repositories" "all" {} data "opslevel_services" "all" {} +data "opslevel_systems" "all" {} + data "opslevel_teams" "all" {} data "opslevel_users" "all" {} diff --git a/tests/data/outputs.tf b/tests/data/outputs.tf index 9a0dee65..8118b726 100644 --- a/tests/data/outputs.tf +++ b/tests/data/outputs.tf @@ -14,6 +14,10 @@ output "all_services" { value = data.opslevel_services.all } +output "all_systems" { + value = data.opslevel_systems.all +} + output "all_teams" { value = data.opslevel_teams.all } @@ -38,6 +42,10 @@ output "first_service" { value = data.opslevel_services.all.services[0] } +output "first_system" { + value = data.opslevel_systems.all.systems[0] +} + output "first_team" { value = data.opslevel_teams.all.teams[0] } diff --git a/tests/filter_predicate_lifecycle_index.tftest.hcl b/tests/filter_predicate_lifecycle_index.tftest.hcl new file mode 100644 index 00000000..e9a0b58d --- /dev/null +++ b/tests/filter_predicate_lifecycle_index.tftest.hcl @@ -0,0 +1,190 @@ +variables { + name = "TF Test Filter with lifecycle_index predicate" + predicate_key = "lifecycle_index" + predicate_value = "1" +} + +run "resource_filter_with_lifecycle_index_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, + distinct([opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value]) + ) + } + +} + +run "resource_filter_with_lifecycle_index_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_lifecycle_index_predicate_gt_eq_or_lt_eq" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_lt_eq_or_gt_eq : { + 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_lt_eq_or_gt_eq, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_lt_eq_or_gt_eq, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_lt_eq_or_gt_eq, + 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, + distinct([opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value]) + ) + } + +} diff --git a/tests/filter_predicate_owner_id.tftest.hcl b/tests/filter_predicate_owner_id.tftest.hcl new file mode 100644 index 00000000..977ad1b6 --- /dev/null +++ b/tests/filter_predicate_owner_id.tftest.hcl @@ -0,0 +1,138 @@ +variables { + name = "TF Test Filter with owner_id predicate" + predicate_key = "owner_id" +} + +run "from_data_module" { + command = plan + plan_options { + target = [ + data.opslevel_teams.all + ] + } + + module { + source = "./data" + } +} + +run "resource_filter_with_owner_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_team.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_team.id, + opslevel_filter.this.predicate[1].value == run.from_data_module.first_team.id + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + run.from_data_module.first_team.id, + distinct([opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value]) + ) + } + +} + +run "resource_filter_with_owner_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_properties.tftest.hcl b/tests/filter_predicate_properties.tftest.hcl new file mode 100644 index 00000000..59a8823d --- /dev/null +++ b/tests/filter_predicate_properties.tftest.hcl @@ -0,0 +1,121 @@ +variables { + name = "TF Test Filter with properties predicate" + jq_expression = ".[] | select(.name == fancy)" + predicate_key = "properties" + predicate_key_data = "property_definition_id" + predicate_type = "satisfies_jq_expression" +} + +run "resource_filter_with_properties_predicate_exists" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_exists : { + key = var.predicate_key + type = predicate_type, + key_data = var.predicate_key_data, + 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 == var.predicate_key_data, + opslevel_filter.this.predicate[1].key_data == var.predicate_key_data + ]) + 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_properties_predicate_satisfies_jq_expression" { + + variables { + predicates = [ + { + key = var.predicate_key + type = var.predicate_type, + key_data = var.predicate_key_data, + value = var.jq_expression + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = opslevel_filter.this.predicate[0].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 + ) + } + + assert { + condition = opslevel_filter.this.predicate[0].type == var.predicate_type + error_message = format( + "expected predicate types to be '%v' got '%v'", + var.predicate_type, + opslevel_filter.this.predicate[0].type + ) + } + + assert { + condition = opslevel_filter.this.predicate[0].key_data == var.predicate_key_data + error_message = format( + "expected predicate types to be '%v' got '%v'", + var.predicate_key_data, + opslevel_filter.this.predicate[0].key_data + ) + } + + assert { + condition = opslevel_filter.this.predicate[0].value == var.jq_expression + error_message = format( + "expected predicate types to be '%v' got '%v'", + var.jq_expression, + opslevel_filter.this.predicate[0].value + ) + } + +} diff --git a/tests/filter_predicate_repository_ids.tftest.hcl b/tests/filter_predicate_repository_ids.tftest.hcl new file mode 100644 index 00000000..a050e082 --- /dev/null +++ b/tests/filter_predicate_repository_ids.tftest.hcl @@ -0,0 +1,63 @@ +variables { + name = "TF Test Filter with repository_ids predicate" + predicate_key = "repository_ids" +} + +run "resource_filter_with_repository_ids_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_system_id.tftest.hcl b/tests/filter_predicate_system_id.tftest.hcl new file mode 100644 index 00000000..f5e27cf1 --- /dev/null +++ b/tests/filter_predicate_system_id.tftest.hcl @@ -0,0 +1,138 @@ +variables { + name = "TF Test Filter with system_id predicate" + predicate_key = "system_id" +} + +run "from_data_module" { + command = plan + plan_options { + target = [ + data.opslevel_systems.all + ] + } + + module { + source = "./data" + } +} + +run "resource_filter_with_system_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_system.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_system.id, + opslevel_filter.this.predicate[1].value == run.from_data_module.first_system.id + ]) + error_message = format( + "expected predicate values to all be '%v' got values '%v'", + run.from_data_module.first_system.id, + distinct([opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value]) + ) + } + +} + +run "resource_filter_with_system_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_tags.tftest.hcl b/tests/filter_predicate_tags.tftest.hcl new file mode 100644 index 00000000..c7d8ab28 --- /dev/null +++ b/tests/filter_predicate_tags.tftest.hcl @@ -0,0 +1,393 @@ +variables { + name = "TF Test Filter with tags predicate" + predicate_key = "tags" + predicate_key_data = "test_tag" + predicate_types_satisfies_version_constraint = "satisfies_version_constraint" + predicate_value = "fancy" +} + +run "resource_filter_with_tags_predicate_contains" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_contains : { + key = var.predicate_key + type = predicate_type, + key_data = var.predicate_key_data, + 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 == var.predicate_key_data, + opslevel_filter.this.predicate[1].key_data == var.predicate_key_data + ]) + error_message = format( + "expected predicate key_data to be '%v' got '%v'", + var.predicate_key_data, + tolist([opslevel_filter.this.predicate[0].key_data, opslevel_filter.this.predicate[1].key_data]) + ) + } + + 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 value to be '%v' got '%v'", + var.predicate_value, + tolist([opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value]) + ) + } + +} + +run "resource_filter_with_tags_predicate_equals" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_equals : { + key = var.predicate_key + type = predicate_type, + key_data = var.predicate_key_data, + 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 == var.predicate_key_data, + opslevel_filter.this.predicate[1].key_data == var.predicate_key_data + ]) + error_message = format( + "expected predicate key_data to be '%v' got '%v'", + var.predicate_key_data, + tolist([opslevel_filter.this.predicate[0].key_data, opslevel_filter.this.predicate[1].key_data]) + ) + } + + 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 value to be '%v' got '%v'", + var.predicate_value, + tolist([opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value]) + ) + } + +} + +run "resource_filter_with_tags_predicate_exists" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_exists : { + key = var.predicate_key + type = predicate_type, + key_data = var.predicate_key_data, + 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 == var.predicate_key_data, + opslevel_filter.this.predicate[1].key_data == var.predicate_key_data + ]) + error_message = format( + "expected predicate key_data to be '%v' got '%v'", + var.predicate_key_data, + tolist([opslevel_filter.this.predicate[0].key_data, opslevel_filter.this.predicate[1].key_data]) + ) + } + + 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_tags_predicate_matches_regex" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_matches_regex : { + key = var.predicate_key + type = predicate_type, + key_data = var.predicate_key_data, + 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 == var.predicate_key_data, + opslevel_filter.this.predicate[1].key_data == var.predicate_key_data + ]) + error_message = format( + "expected predicate key_data to be '%v' got '%v'", + var.predicate_key_data, + tolist([opslevel_filter.this.predicate[0].key_data, opslevel_filter.this.predicate[1].key_data]) + ) + } + + 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 value to be '%v' got '%v'", + var.predicate_value, + tolist([opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value]) + ) + } + +} + +run "resource_filter_with_tags_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 = var.predicate_key_data, + 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 == var.predicate_key_data, + opslevel_filter.this.predicate[1].key_data == var.predicate_key_data + ]) + error_message = format( + "expected predicate key_data to be '%v' got '%v'", + var.predicate_key_data, + tolist([opslevel_filter.this.predicate[0].key_data, opslevel_filter.this.predicate[1].key_data]) + ) + } + + 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 value to be '%v' got '%v'", + var.predicate_value, + tolist([opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value]) + ) + } + +} + +run "resource_filter_with_tags_predicate_satisfies_version_constraint" { + + variables { + predicates = [ + { + key = var.predicate_key + type = var.predicate_types_satisfies_version_constraint, + key_data = var.predicate_key_data, + value = var.predicate_value + } + ] + } + + module { + source = "./opslevel_modules/modules/filter" + } + + assert { + condition = opslevel_filter.this.predicate[0].key == var.predicate_key + error_message = format( + "expected predicate key to be '%v' got key '%v'", + var.predicate_key, + opslevel_filter.this.predicate[0].key + ) + } + + assert { + condition = opslevel_filter.this.predicate[0].type == var.predicate_types_satisfies_version_constraint + error_message = format( + "expected predicate type to be '%v' got '%v'", + var.predicate_types_satisfies_version_constraint, + opslevel_filter.this.predicate[0].type + ) + } + + assert { + condition = opslevel_filter.this.predicate[0].key_data == var.predicate_key_data + error_message = format( + "expected predicate key_data to be '%v' got '%v'", + var.predicate_key_data, + opslevel_filter.this.predicate[0].key_data + ) + } + + assert { + condition = opslevel_filter.this.predicate[0].value == var.predicate_value + error_message = format( + "expected predicate value to be '%v' got '%v'", + var.predicate_value, + opslevel_filter.this.predicate[0].value + ) + } + +} diff --git a/tests/filter_predicate_tier_index.tftest.hcl b/tests/filter_predicate_tier_index.tftest.hcl new file mode 100644 index 00000000..78e105e2 --- /dev/null +++ b/tests/filter_predicate_tier_index.tftest.hcl @@ -0,0 +1,191 @@ +variables { + name = "TF Test Filter with tier_index predicate" + predicate_key = "tier_index" + predicate_value = "1" +} + +run "resource_filter_with_tier_index_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, + distinct([opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value]) + ) + } + +} + +run "resource_filter_with_tier_index_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_tier_index_predicate_gt_eq_or_lt_eq" { + + variables { + predicates = [ + for predicate_type in var.predicate_types_lt_eq_or_gt_eq : { + 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_lt_eq_or_gt_eq, opslevel_filter.this.predicate[0].type), + contains(var.predicate_types_lt_eq_or_gt_eq, opslevel_filter.this.predicate[1].type) + ]) + error_message = format( + "expected predicate types to be one of '%v' got '%v'", + var.predicate_types_lt_eq_or_gt_eq, + 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, + distinct([opslevel_filter.this.predicate[0].value, opslevel_filter.this.predicate[1].value]) + ) + } + +} + diff --git a/tests/opslevel_modules b/tests/opslevel_modules index a7652752..6944b330 160000 --- a/tests/opslevel_modules +++ b/tests/opslevel_modules @@ -1 +1 @@ -Subproject commit a76527524e856f4020b5a7601f6f2682d129e5f1 +Subproject commit 6944b3308ef09fdae31c0a32dd95ad3ff2ae5384 diff --git a/tests/remote/filter_predicate_lifecycle_index.tftest.hcl b/tests/remote/filter_predicate_lifecycle_index.tftest.hcl deleted file mode 100644 index 71694e37..00000000 --- a/tests/remote/filter_predicate_lifecycle_index.tftest.hcl +++ /dev/null @@ -1,264 +0,0 @@ -variables { - name = "TF Test Filter with lifecycle_index predicate" - predicate_value = "1" - lifecycle_index_predicates = setproduct( - ["lifecycle_index"], - concat( - ["less_than_or_equal_to", "greater_than_or_equal_to"], - var.predicate_types_equals, - var.predicate_types_exists - ), - ) -} - -run "resource_filter_with_lifecycle_index_predicate_equals" { - - variables { - predicates = tomap({ - for pair in var.lifecycle_index_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["lifecycle_index_does_not_equal"].predicate[0].key == "lifecycle_index" - error_message = format( - "expected predicate key 'lifecycle_index' got '%s'", - opslevel_filter.all_predicates["lifecycle_index_does_not_equal"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_does_not_equal"].predicate[0].type == "does_not_equal" - error_message = format( - "expected predicate type 'does_not_equal' got '%s'", - opslevel_filter.all_predicates["lifecycle_index_does_not_equal"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_does_not_equal"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_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["lifecycle_index_does_not_equal"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_equals"].predicate[0].key == "lifecycle_index" - error_message = format( - "expected predicate key 'lifecycle_index' got '%s'", - opslevel_filter.all_predicates["lifecycle_index_equals"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_equals"].predicate[0].type == "equals" - error_message = format( - "expected predicate type 'equals' got '%s'", - opslevel_filter.all_predicates["lifecycle_index_equals"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_equals"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_equals"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["lifecycle_index_equals"].predicate[0].value - ) - } - -} - -run "resource_filter_with_lifecycle_index_predicate_exists" { - - variables { - predicates = tomap({ - for pair in var.lifecycle_index_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["lifecycle_index_does_not_exist"].predicate[0].key == "lifecycle_index" - error_message = format( - "expected predicate key 'lifecycle_index' got '%s'", - opslevel_filter.all_predicates["lifecycle_index_does_not_exist"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_does_not_exist"].predicate[0].type == "does_not_exist" - error_message = format( - "expected predicate type 'does_not_exist' got '%s'", - opslevel_filter.all_predicates["lifecycle_index_does_not_exist"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_does_not_exist"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_does_not_exist"].predicate[0].value == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_exists"].predicate[0].key == "lifecycle_index" - error_message = format( - "expected predicate key 'lifecycle_index' got '%s'", - opslevel_filter.all_predicates["lifecycle_index_exists"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_exists"].predicate[0].type == "exists" - error_message = format( - "expected predicate type 'exists' got '%s'", - opslevel_filter.all_predicates["lifecycle_index_exists"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_exists"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_exists"].predicate[0].value == null - error_message = var.error_expected_null_field - } - -} - -run "resource_filter_with_lifecycle_index_predicate_greater_than_or_equal_to" { - - variables { - predicates = tomap({ - for pair in var.lifecycle_index_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if "greater_than_or_equal_to" == pair[1] - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_greater_than_or_equal_to"].predicate[0].key == "lifecycle_index" - error_message = format( - "expected predicate key 'lifecycle_index' got '%s'", - opslevel_filter.all_predicates["lifecycle_index_greater_than_or_equal_to"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_greater_than_or_equal_to"].predicate[0].type == "greater_than_or_equal_to" - error_message = format( - "expected predicate type 'greater_than_or_equal_to' got '%s'", - opslevel_filter.all_predicates["lifecycle_index_greater_than_or_equal_to"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_greater_than_or_equal_to"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_greater_than_or_equal_to"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["lifecycle_index_greater_than_or_equal_to"].predicate[0].value - ) - } - -} - -run "resource_filter_with_lifecycle_index_predicate_less_than_or_equal_to" { - - variables { - predicates = tomap({ - for pair in var.lifecycle_index_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if "less_than_or_equal_to" == pair[1] - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_less_than_or_equal_to"].predicate[0].key == "lifecycle_index" - error_message = format( - "expected predicate key 'lifecycle_index' got '%s'", - opslevel_filter.all_predicates["lifecycle_index_less_than_or_equal_to"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_less_than_or_equal_to"].predicate[0].type == "less_than_or_equal_to" - error_message = format( - "expected predicate type 'less_than_or_equal_to' got '%s'", - opslevel_filter.all_predicates["lifecycle_index_less_than_or_equal_to"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_less_than_or_equal_to"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["lifecycle_index_less_than_or_equal_to"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["lifecycle_index_less_than_or_equal_to"].predicate[0].value - ) - } - -} diff --git a/tests/remote/filter_predicate_owner_id.tftest.hcl b/tests/remote/filter_predicate_owner_id.tftest.hcl deleted file mode 100644 index 47530e90..00000000 --- a/tests/remote/filter_predicate_owner_id.tftest.hcl +++ /dev/null @@ -1,171 +0,0 @@ -variables { - name = "TF Test Filter with owner_id predicate" - owner_id_predicates = setproduct( - ["owner_id"], - concat(var.predicate_types_equals, var.predicate_types_exists) - ) -} - -run "get_team" { - command = plan - - variables { - name = "placeholder" - } - - module { - source = "./team" - } -} - -run "resource_filter_with_owner_id_predicate_equals" { - - variables { - predicates = tomap({ - for pair in var.owner_id_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = run.get_team.first_team.id - } - if contains(var.predicate_types_equals, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["owner_id_does_not_equal"].predicate[0].key == "owner_id" - error_message = format( - "expected predicate key 'owner_id' got '%s'", - opslevel_filter.all_predicates["owner_id_does_not_equal"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["owner_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["owner_id_does_not_equal"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["owner_id_does_not_equal"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["owner_id_does_not_equal"].predicate[0].value == run.get_team.first_team.id - error_message = format( - "expected predicate value '%s' got '%s'", - run.get_team.first_team.id, - opslevel_filter.all_predicates["owner_id_does_not_equal"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["owner_id_equals"].predicate[0].key == "owner_id" - error_message = format( - "expected predicate key 'owner_id' got '%s'", - opslevel_filter.all_predicates["owner_id_equals"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["owner_id_equals"].predicate[0].type == "equals" - error_message = format( - "expected predicate type 'equals' got '%s'", - opslevel_filter.all_predicates["owner_id_equals"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["owner_id_equals"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["owner_id_equals"].predicate[0].value == run.get_team.first_team.id - error_message = format( - "expected predicate value '%s' got '%s'", - run.get_team.first_team.id, - opslevel_filter.all_predicates["owner_id_equals"].predicate[0].type - ) - } - -} - -run "resource_filter_with_owner_id_predicate_exists" { - - variables { - predicates = tomap({ - for pair in var.owner_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["owner_id_does_not_exist"].predicate[0].key == "owner_id" - error_message = format( - "expected predicate key 'owner_id' got '%s'", - opslevel_filter.all_predicates["owner_id_does_not_exist"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["owner_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["owner_id_does_not_exist"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["owner_id_does_not_exist"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["owner_id_does_not_exist"].predicate[0].value == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["owner_id_exists"].predicate[0].key == "owner_id" - error_message = format( - "expected predicate key 'owner_id' got '%s'", - opslevel_filter.all_predicates["owner_id_exists"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["owner_id_exists"].predicate[0].type == "exists" - error_message = format( - "expected predicate type 'exists' got '%s'", - opslevel_filter.all_predicates["owner_id_exists"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["owner_id_exists"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["owner_id_exists"].predicate[0].value == null - error_message = var.error_expected_null_field - } - -} diff --git a/tests/remote/filter_predicate_properties.tftest.hcl b/tests/remote/filter_predicate_properties.tftest.hcl deleted file mode 100644 index ff1a8711..00000000 --- a/tests/remote/filter_predicate_properties.tftest.hcl +++ /dev/null @@ -1,142 +0,0 @@ -variables { - name = "TF Test Filter with properties predicate" - jq_expression = ".[] | select(.name == fancy)" - predicate_key_data = "property_definition_id" - properties_predicates = setproduct(["properties"], concat(var.predicate_types_exists, ["satisfies_jq_expression"])) -} - -run "resource_filter_with_properties_predicate_exists" { - - variables { - connective = "and" - predicates = tomap({ - for pair in var.properties_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = var.predicate_key_data, - value = null - } - if contains(var.predicate_types_exists, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["properties_does_not_exist"].predicate[0].key == "properties" - error_message = format( - "expected predicate key 'properties' got '%s'", - opslevel_filter.all_predicates["properties_does_not_exist"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["properties_does_not_exist"].predicate[0].type == "does_not_exist" - error_message = format( - "expected predicate type 'does_not_exist' got '%s'", - opslevel_filter.all_predicates["properties_does_not_exist"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["properties_does_not_exist"].predicate[0].key_data == var.predicate_key_data - error_message = format( - "expected predicate key_data '%s' got '%s'", - var.predicate_key_data, - opslevel_filter.all_predicates["properties_does_not_exist"].predicate[0].key_data - ) - } - - assert { - condition = opslevel_filter.all_predicates["properties_does_not_exist"].predicate[0].value == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["properties_exists"].predicate[0].key == "properties" - error_message = format( - "expected predicate key 'properties' got '%s'", - opslevel_filter.all_predicates["properties_exists"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["properties_exists"].predicate[0].type == "exists" - error_message = format( - "expected predicate type 'exists' got '%s'", - opslevel_filter.all_predicates["properties_exists"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["properties_exists"].predicate[0].key_data == var.predicate_key_data - error_message = format( - "expected predicate key_data '%s' got '%s'", - var.predicate_key_data, - opslevel_filter.all_predicates["properties_exists"].predicate[0].key_data - ) - } - - assert { - condition = opslevel_filter.all_predicates["properties_exists"].predicate[0].value == null - error_message = var.error_expected_null_field - } - -} - -run "resource_filter_with_properties_predicate_satisfies_jq_expression" { - - variables { - connective = "and" - predicates = tomap({ - for pair in var.properties_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = var.predicate_key_data, - value = var.jq_expression - } - if "satisfies_jq_expression" == pair[1] - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["properties_satisfies_jq_expression"].predicate[0].key == "properties" - error_message = format( - "expected predicate key 'properties' got '%s'", - opslevel_filter.all_predicates["properties_satisfies_jq_expression"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["properties_satisfies_jq_expression"].predicate[0].type == "satisfies_jq_expression" - error_message = format( - "expected predicate type 'satisfies_jq_expression' got '%s'", - opslevel_filter.all_predicates["properties_satisfies_jq_expression"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["properties_satisfies_jq_expression"].predicate[0].key_data == var.predicate_key_data - error_message = format( - "expected predicate key_data '%s' got '%s'", - var.predicate_key_data, - opslevel_filter.all_predicates["properties_satisfies_jq_expression"].predicate[0].key_data - ) - } - - assert { - condition = opslevel_filter.all_predicates["properties_satisfies_jq_expression"].predicate[0].value == var.jq_expression - error_message = format( - "expected predicate value '%s' got '%s'", - var.jq_expression, - opslevel_filter.all_predicates["properties_satisfies_jq_expression"].predicate[0].type - ) - } - -} diff --git a/tests/remote/filter_predicate_repository_ids.tftest.hcl b/tests/remote/filter_predicate_repository_ids.tftest.hcl deleted file mode 100644 index 93a9be6f..00000000 --- a/tests/remote/filter_predicate_repository_ids.tftest.hcl +++ /dev/null @@ -1,75 +0,0 @@ -variables { - name = "TF Test Filter with repository_ids predicate" - repository_ids_predicates = setproduct(["repository_ids"], var.predicate_types_exists) -} - -run "resource_filter_with_repository_ids_predicate_exists" { - - variables { - predicates = tomap({ - for pair in var.repository_ids_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = null - } - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["repository_ids_does_not_exist"].predicate[0].key == "repository_ids" - error_message = format( - "expected predicate key 'repository_ids' got '%s'", - opslevel_filter.all_predicates["repository_ids_does_not_exist"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["repository_ids_does_not_exist"].predicate[0].type == "does_not_exist" - error_message = format( - "expected predicate type 'does_not_exist' got '%s'", - opslevel_filter.all_predicates["repository_ids_does_not_exist"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["repository_ids_does_not_exist"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["repository_ids_does_not_exist"].predicate[0].value == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["repository_ids_exists"].predicate[0].key == "repository_ids" - error_message = format( - "expected predicate key 'repository_ids' got '%s'", - opslevel_filter.all_predicates["repository_ids_exists"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["repository_ids_exists"].predicate[0].type == "exists" - error_message = format( - "expected predicate type 'exists' got '%s'", - opslevel_filter.all_predicates["repository_ids_exists"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["repository_ids_exists"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["repository_ids_exists"].predicate[0].value == null - error_message = var.error_expected_null_field - } - -} diff --git a/tests/remote/filter_predicate_system_id.tftest.hcl b/tests/remote/filter_predicate_system_id.tftest.hcl deleted file mode 100644 index 603dc3a5..00000000 --- a/tests/remote/filter_predicate_system_id.tftest.hcl +++ /dev/null @@ -1,171 +0,0 @@ -variables { - name = "TF Test Filter with system_id predicate" - system_id_predicates = setproduct( - ["system_id"], - concat(var.predicate_types_equals, var.predicate_types_exists) - ) -} - -run "get_system" { - command = plan - - variables { - name = "placeholder" - } - - module { - source = "./system" - } -} - -run "resource_filter_with_system_id_predicate_equals" { - - variables { - predicates = tomap({ - for pair in var.system_id_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = run.get_system.first_system.id - } - if contains(var.predicate_types_equals, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["system_id_does_not_equal"].predicate[0].key == "system_id" - error_message = format( - "expected predicate key 'system_id' got '%s'", - opslevel_filter.all_predicates["system_id_does_not_equal"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["system_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["system_id_does_not_equal"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["system_id_does_not_equal"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["system_id_does_not_equal"].predicate[0].value == run.get_system.first_system.id - error_message = format( - "expected predicate value '%s' got '%s'", - run.get_system.first_system.id, - opslevel_filter.all_predicates["system_id_does_not_equal"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["system_id_equals"].predicate[0].key == "system_id" - error_message = format( - "expected predicate key 'system_id' got '%s'", - opslevel_filter.all_predicates["system_id_equals"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["system_id_equals"].predicate[0].type == "equals" - error_message = format( - "expected predicate type 'equals' got '%s'", - opslevel_filter.all_predicates["system_id_equals"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["system_id_equals"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["system_id_equals"].predicate[0].value == run.get_system.first_system.id - error_message = format( - "expected predicate value '%s' got '%s'", - run.get_system.first_system.id, - opslevel_filter.all_predicates["system_id_equals"].predicate[0].type - ) - } - -} - -run "resource_filter_with_system_id_predicate_exists" { - - variables { - predicates = tomap({ - for pair in var.system_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["system_id_does_not_exist"].predicate[0].key == "system_id" - error_message = format( - "expected predicate key 'system_id' got '%s'", - opslevel_filter.all_predicates["system_id_does_not_exist"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["system_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["system_id_does_not_exist"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["system_id_does_not_exist"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["system_id_does_not_exist"].predicate[0].value == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["system_id_exists"].predicate[0].key == "system_id" - error_message = format( - "expected predicate key 'system_id' got '%s'", - opslevel_filter.all_predicates["system_id_exists"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["system_id_exists"].predicate[0].type == "exists" - error_message = format( - "expected predicate type 'exists' got '%s'", - opslevel_filter.all_predicates["system_id_exists"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["system_id_exists"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["system_id_exists"].predicate[0].value == null - error_message = var.error_expected_null_field - } - -} diff --git a/tests/remote/filter_predicate_tags.tftest.hcl b/tests/remote/filter_predicate_tags.tftest.hcl deleted file mode 100644 index 96b173cf..00000000 --- a/tests/remote/filter_predicate_tags.tftest.hcl +++ /dev/null @@ -1,508 +0,0 @@ -variables { - name = "TF Test Filter with tags predicate" - predicate_key_data = "test_tag" - predicate_value = "fancy" - tags_predicates = setproduct( - ["tags"], - concat( - ["satisfies_version_constraint"], - 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_tags_predicate_contains" { - - variables { - connective = "and" - predicates = tomap({ - for pair in var.tags_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = var.predicate_key_data, - value = var.predicate_value - } - if contains(var.predicate_types_contains, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["tags_does_not_contain"].predicate[0].key == "tags" - error_message = format( - "expected predicate key 'tags' got '%s'", - opslevel_filter.all_predicates["tags_does_not_contain"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_does_not_contain"].predicate[0].type == "does_not_contain" - error_message = format( - "expected predicate type 'does_not_contain' got '%s'", - opslevel_filter.all_predicates["tags_does_not_contain"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_does_not_contain"].predicate[0].key_data == var.predicate_key_data - error_message = format( - "expected predicate key_data '%s' got '%s'", - var.predicate_key_data, - opslevel_filter.all_predicates["tags_does_not_contain"].predicate[0].key_data - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_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["tags_does_not_contain"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_contains"].predicate[0].key == "tags" - error_message = format( - "expected predicate key 'tags' got '%s'", - opslevel_filter.all_predicates["tags_contains"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_contains"].predicate[0].type == "contains" - error_message = format( - "expected predicate type 'contains' got '%s'", - opslevel_filter.all_predicates["tags_contains"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_contains"].predicate[0].key_data == var.predicate_key_data - error_message = format( - "expected predicate key_data '%s' got '%s'", - var.predicate_key_data, - opslevel_filter.all_predicates["tags_contains"].predicate[0].key_data - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_contains"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["tags_contains"].predicate[0].value - ) - } - -} - -run "resource_filter_with_tags_predicate_equals" { - - variables { - connective = "and" - predicates = tomap({ - for pair in var.tags_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = var.predicate_key_data, - value = var.predicate_value - } - if contains(var.predicate_types_equals, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["tags_does_not_equal"].predicate[0].key == "tags" - error_message = format( - "expected predicate key 'tags' got '%s'", - opslevel_filter.all_predicates["tags_does_not_equal"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_does_not_equal"].predicate[0].type == "does_not_equal" - error_message = format( - "expected predicate type 'does_not_equal' got '%s'", - opslevel_filter.all_predicates["tags_does_not_equal"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_does_not_equal"].predicate[0].key_data == var.predicate_key_data - error_message = format( - "expected predicate key_data '%s' got '%s'", - var.predicate_key_data, - opslevel_filter.all_predicates["tags_does_not_equal"].predicate[0].key_data - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_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["tags_does_not_equal"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_equals"].predicate[0].key == "tags" - error_message = format( - "expected predicate key 'tags' got '%s'", - opslevel_filter.all_predicates["tags_equals"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_equals"].predicate[0].type == "equals" - error_message = format( - "expected predicate type 'equals' got '%s'", - opslevel_filter.all_predicates["tags_equals"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_equals"].predicate[0].key_data == var.predicate_key_data - error_message = format( - "expected predicate key_data '%s' got '%s'", - var.predicate_key_data, - opslevel_filter.all_predicates["tags_equals"].predicate[0].key_data - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_equals"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["tags_equals"].predicate[0].value - ) - } - -} - -run "resource_filter_with_tags_predicate_exists" { - - variables { - connective = "and" - predicates = tomap({ - for pair in var.tags_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = var.predicate_key_data, - value = null - } - if contains(var.predicate_types_exists, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["tags_does_not_exist"].predicate[0].key == "tags" - error_message = format( - "expected predicate key 'tags' got '%s'", - opslevel_filter.all_predicates["tags_does_not_exist"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_does_not_exist"].predicate[0].type == "does_not_exist" - error_message = format( - "expected predicate type 'does_not_exist' got '%s'", - opslevel_filter.all_predicates["tags_does_not_exist"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_does_not_exist"].predicate[0].key_data == var.predicate_key_data - error_message = format( - "expected predicate key_data '%s' got '%s'", - var.predicate_key_data, - opslevel_filter.all_predicates["tags_does_not_exist"].predicate[0].key_data - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_does_not_exist"].predicate[0].value == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["tags_exists"].predicate[0].key == "tags" - error_message = format( - "expected predicate key 'tags' got '%s'", - opslevel_filter.all_predicates["tags_exists"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_exists"].predicate[0].type == "exists" - error_message = format( - "expected predicate type 'exists' got '%s'", - opslevel_filter.all_predicates["tags_exists"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_exists"].predicate[0].key_data == var.predicate_key_data - error_message = format( - "expected predicate key_data '%s' got '%s'", - var.predicate_key_data, - opslevel_filter.all_predicates["tags_exists"].predicate[0].key_data - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_exists"].predicate[0].value == null - error_message = var.error_expected_null_field - } - -} - -run "resource_filter_with_tags_predicate_matches_regex" { - - variables { - connective = "and" - predicates = tomap({ - for pair in var.tags_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = var.predicate_key_data, - value = var.predicate_value - } - if contains(var.predicate_types_matches_regex, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["tags_does_not_match_regex"].predicate[0].key == "tags" - error_message = format( - "expected predicate key 'tags' got '%s'", - opslevel_filter.all_predicates["tags_does_not_match_regex"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_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["tags_does_not_match_regex"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_does_not_match_regex"].predicate[0].key_data == var.predicate_key_data - error_message = format( - "expected predicate key_data '%s' got '%s'", - var.predicate_key_data, - opslevel_filter.all_predicates["tags_does_not_match_regex"].predicate[0].key_data - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_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["tags_does_not_match_regex"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_matches_regex"].predicate[0].key == "tags" - error_message = format( - "expected predicate key 'tags' got '%s'", - opslevel_filter.all_predicates["tags_matches_regex"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_matches_regex"].predicate[0].type == "matches_regex" - error_message = format( - "expected predicate type 'matches_regex' got '%s'", - opslevel_filter.all_predicates["tags_matches_regex"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_matches_regex"].predicate[0].key_data == var.predicate_key_data - error_message = format( - "expected predicate key_data '%s' got '%s'", - var.predicate_key_data, - opslevel_filter.all_predicates["tags_matches_regex"].predicate[0].key_data - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_matches_regex"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["tags_matches_regex"].predicate[0].value - ) - } - -} - -run "resource_filter_with_tags_predicate_starts_or_ends_with" { - - variables { - connective = "and" - predicates = tomap({ - for pair in var.tags_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = var.predicate_key_data, - value = var.predicate_value - } - if contains(var.predicate_types_ends_or_starts_with, pair[1]) - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["tags_ends_with"].predicate[0].key == "tags" - error_message = format( - "expected predicate key 'tags' got '%s'", - opslevel_filter.all_predicates["tags_ends_with"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_ends_with"].predicate[0].type == "ends_with" - error_message = format( - "expected predicate type 'ends_with' got '%s'", - opslevel_filter.all_predicates["tags_ends_with"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_ends_with"].predicate[0].key_data == var.predicate_key_data - error_message = format( - "expected predicate key_data '%s' got '%s'", - var.predicate_key_data, - opslevel_filter.all_predicates["tags_ends_with"].predicate[0].key_data - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_ends_with"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["tags_ends_with"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_starts_with"].predicate[0].key == "tags" - error_message = format( - "expected predicate key 'tags' got '%s'", - opslevel_filter.all_predicates["tags_starts_with"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_starts_with"].predicate[0].type == "starts_with" - error_message = format( - "expected predicate type 'starts_with' got '%s'", - opslevel_filter.all_predicates["tags_starts_with"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_starts_with"].predicate[0].key_data == var.predicate_key_data - error_message = format( - "expected predicate key_data '%s' got '%s'", - var.predicate_key_data, - opslevel_filter.all_predicates["tags_starts_with"].predicate[0].key_data - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_starts_with"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["tags_starts_with"].predicate[0].value - ) - } - -} - -run "resource_filter_with_tags_predicate_satisfies_version_constraint" { - - variables { - connective = "and" - predicates = tomap({ - for pair in var.tags_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = var.predicate_key_data, - value = var.predicate_value - } - if "satisfies_version_constraint" == pair[1] - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["tags_satisfies_version_constraint"].predicate[0].key == "tags" - error_message = format( - "expected predicate key 'tags' got '%s'", - opslevel_filter.all_predicates["tags_satisfies_version_constraint"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_satisfies_version_constraint"].predicate[0].type == "satisfies_version_constraint" - error_message = format( - "expected predicate type 'satisfies_version_constraint' got '%s'", - opslevel_filter.all_predicates["tags_satisfies_version_constraint"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_satisfies_version_constraint"].predicate[0].key_data == var.predicate_key_data - error_message = format( - "expected predicate key_data '%s' got '%s'", - var.predicate_key_data, - opslevel_filter.all_predicates["tags_satisfies_version_constraint"].predicate[0].key_data - ) - } - - assert { - condition = opslevel_filter.all_predicates["tags_satisfies_version_constraint"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["tags_satisfies_version_constraint"].predicate[0].value - ) - } - -} diff --git a/tests/remote/filter_predicate_tier_index.tftest.hcl b/tests/remote/filter_predicate_tier_index.tftest.hcl deleted file mode 100644 index 37adf04b..00000000 --- a/tests/remote/filter_predicate_tier_index.tftest.hcl +++ /dev/null @@ -1,264 +0,0 @@ -variables { - name = "TF Test Filter with tier_index predicate" - predicate_value = "1" - tier_index_predicates = setproduct( - ["tier_index"], - concat( - ["less_than_or_equal_to", "greater_than_or_equal_to"], - var.predicate_types_equals, - var.predicate_types_exists - ), - ) -} - -run "resource_filter_with_tier_index_predicate_equals" { - - variables { - predicates = tomap({ - for pair in var.tier_index_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["tier_index_does_not_equal"].predicate[0].key == "tier_index" - error_message = format( - "expected predicate key 'tier_index' got '%s'", - opslevel_filter.all_predicates["tier_index_does_not_equal"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_does_not_equal"].predicate[0].type == "does_not_equal" - error_message = format( - "expected predicate type 'does_not_equal' got '%s'", - opslevel_filter.all_predicates["tier_index_does_not_equal"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_does_not_equal"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_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["tier_index_does_not_equal"].predicate[0].value - ) - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_equals"].predicate[0].key == "tier_index" - error_message = format( - "expected predicate key 'tier_index' got '%s'", - opslevel_filter.all_predicates["tier_index_equals"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_equals"].predicate[0].type == "equals" - error_message = format( - "expected predicate type 'does_not_equal' got '%s'", - opslevel_filter.all_predicates["tier_index_equals"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_equals"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_equals"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["tier_index_equals"].predicate[0].value - ) - } - -} - -run "resource_filter_with_tier_index_predicate_exists" { - - variables { - predicates = tomap({ - for pair in var.tier_index_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["tier_index_does_not_exist"].predicate[0].key == "tier_index" - error_message = format( - "expected predicate key 'tier_index' got '%s'", - opslevel_filter.all_predicates["tier_index_does_not_exist"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_does_not_exist"].predicate[0].type == "does_not_exist" - error_message = format( - "expected predicate type 'does_not_exist' got '%s'", - opslevel_filter.all_predicates["tier_index_does_not_exist"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_does_not_exist"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_does_not_exist"].predicate[0].value == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_exists"].predicate[0].key == "tier_index" - error_message = format( - "expected predicate key 'tier_index' got '%s'", - opslevel_filter.all_predicates["tier_index_exists"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_exists"].predicate[0].type == "exists" - error_message = format( - "expected predicate type 'exists' got '%s'", - opslevel_filter.all_predicates["tier_index_exists"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_exists"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_exists"].predicate[0].value == null - error_message = var.error_expected_null_field - } - -} - -run "resource_filter_with_tier_index_predicate_greater_than_or_equal_to" { - - variables { - predicates = tomap({ - for pair in var.tier_index_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if "greater_than_or_equal_to" == pair[1] - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_greater_than_or_equal_to"].predicate[0].key == "tier_index" - error_message = format( - "expected predicate key 'tier_index' got '%s'", - opslevel_filter.all_predicates["tier_index_greater_than_or_equal_to"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_greater_than_or_equal_to"].predicate[0].type == "greater_than_or_equal_to" - error_message = format( - "expected predicate type 'greater_than_or_equal_to' got '%s'", - opslevel_filter.all_predicates["tier_index_greater_than_or_equal_to"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_greater_than_or_equal_to"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_greater_than_or_equal_to"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["tier_index_greater_than_or_equal_to"].predicate[0].value - ) - } - -} - -run "resource_filter_with_tier_index_predicate_less_than_or_equal_to" { - - variables { - predicates = tomap({ - for pair in var.tier_index_predicates : "${pair[0]}_${pair[1]}" => { - key = pair[0], - type = pair[1], - key_data = null, - value = var.predicate_value - } - if "less_than_or_equal_to" == pair[1] - }) - } - - module { - source = "./filter" - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_less_than_or_equal_to"].predicate[0].key == "tier_index" - error_message = format( - "expected predicate key 'tier_index' got '%s'", - opslevel_filter.all_predicates["tier_index_less_than_or_equal_to"].predicate[0].key - ) - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_less_than_or_equal_to"].predicate[0].type == "less_than_or_equal_to" - error_message = format( - "expected predicate type 'less_than_or_equal_to' got '%s'", - opslevel_filter.all_predicates["tier_index_less_than_or_equal_to"].predicate[0].type - ) - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_less_than_or_equal_to"].predicate[0].key_data == null - error_message = var.error_expected_null_field - } - - assert { - condition = opslevel_filter.all_predicates["tier_index_less_than_or_equal_to"].predicate[0].value == var.predicate_value - error_message = format( - "expected predicate value '%s' got '%s'", - var.predicate_value, - opslevel_filter.all_predicates["tier_index_less_than_or_equal_to"].predicate[0].value - ) - } - -} diff --git a/tests/test.tfvars b/tests/test.tfvars index 4bcf736f..feb34d1c 100644 --- a/tests/test.tfvars +++ b/tests/test.tfvars @@ -70,6 +70,7 @@ error_wrong_value = "wrong value for 'TYPE'" id_prefix = "Z2lkOi8v" predicate_types_contains = ["does_not_contain", "contains"] predicate_types_ends_or_starts_with = ["ends_with", "starts_with"] +predicate_types_lt_eq_or_gt_eq = ["less_than_or_equal_to", "greater_than_or_equal_to"] predicate_types_matches_regex = ["does_not_match_regex", "matches_regex"] predicate_types_equals = ["does_not_equal", "equals"] predicate_types_exists = ["does_not_exist", "exists"]