Skip to content

Commit

Permalink
Fix test comparison.
Browse files Browse the repository at this point in the history
  • Loading branch information
korenyoni committed Oct 17, 2023
1 parent 65e1923 commit 6743d68
Show file tree
Hide file tree
Showing 62 changed files with 4,705 additions and 305 deletions.
5 changes: 5 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ equivalence: build
@echo "==> Running equivalence tests for opentofu"
cd testing/equivalence;\
equivalence-testing update --binary=$$(which tofu) --goldens=results/opentofu --tests=test_cases --rewrites=rewrites.jsonc

@echo "==> Comparing results"
cd testing/equivalence;\
./compare-results.sh;\

fmt:
@echo "==> Fixing source code with gofmt..."
gofmt -s -w $(GOFMT_FILES)
Expand Down
4 changes: 0 additions & 4 deletions examples/.modules/account_token/provider.tf

This file was deleted.

10 changes: 0 additions & 10 deletions examples/.modules/account_token/vars.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
variable api_url {
type = string
}

#
variable token {
type = string
default = ""
}

variable account_id {
type = string
default = ""
Expand Down
8 changes: 8 additions & 0 deletions examples/.modules/account_token/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
codefresh = {
source = "registry.terraform.io/codefresh-io/codefresh"
version = "~> 0.1"
}
}
}
4 changes: 0 additions & 4 deletions examples/.modules/account_tokens/provider.tf

This file was deleted.

11 changes: 0 additions & 11 deletions examples/.modules/account_tokens/vars.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
variable api_url {
type = string
}

#
variable admin_token {
type = string
default = ""
}


## Set of account names
variable accounts {
type = set(string)
Expand Down
8 changes: 8 additions & 0 deletions examples/.modules/account_tokens/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
codefresh = {
source = "registry.terraform.io/codefresh-io/codefresh"
version = "~> 0.1"
}
}
}
4 changes: 0 additions & 4 deletions examples/.modules/accounts_users/provider.tf

This file was deleted.

8 changes: 8 additions & 0 deletions examples/.modules/accounts_users/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
codefresh = {
source = "registry.terraform.io/codefresh-io/codefresh"
version = "~> 0.1"
}
}
}
14 changes: 0 additions & 14 deletions examples/.modules/teams/vars.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
# variable api_url {
# type = string
# }

# variable token {
# type = string
# default = ""
# }

# teams map[team_name]usersList
# {
# developers = ["user1", "user3"]
# managers = ["user3", "user2"]
# }
variable teams {
type = map(any)
}
8 changes: 8 additions & 0 deletions examples/.modules/teams/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
codefresh = {
source = "registry.terraform.io/codefresh-io/codefresh"
version = "~> 0.1"
}
}
}
11 changes: 0 additions & 11 deletions examples/account_tokens/main.tf
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
variable "api_url" {
type = string
}

#
variable "token" {
type = string
default = ""
}

## Set of account names
variable "accounts" {
type = set(string)
}

module "account_tokens" {
source = "../.modules/account_tokens"
api_url = var.api_url
accounts = var.accounts
}

Expand Down
2 changes: 0 additions & 2 deletions examples/account_tokens/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
api_url = "https://my-codefresh-example.com/api"

accounts = [
"acc1", "acc2"
]
4 changes: 4 additions & 0 deletions examples/teams/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
variable "teams" {
type = map(any)
default = {
developers = ["user1", "user3"]
managers = ["user3", "user2"]
}
}

module "teams" {
Expand Down
4 changes: 0 additions & 4 deletions examples/teams/terraform.tfvars

This file was deleted.

11 changes: 8 additions & 3 deletions testing/equivalence/compare-results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source $(realpath $(dirname $0))/lib.sh

for i in $(find $(realpath $(dirname $0))/results/terraform -mindepth 1 -not -path '**/*/.*' -type d); do
for i in $(find $(realpath $(dirname $0))/results/terraform -mindepth 1 -maxdepth 1 -type d); do
test_case_name=$(basename ${i})
print_style "Test case "
print_style "${test_case_name}" "info"
Expand All @@ -13,9 +13,14 @@ for i in $(find $(realpath $(dirname $0))/results/terraform -mindepth 1 -not -pa
print_style " and "
print_style "results/opentofu/$(basename ${f})" "info"
print_style ": "

terraform_file=$(realpath $(dirname $0))/results/terraform/$(basename ${i})/$(basename ${f})
opentofu_file=$(realpath $(dirname $0))/results/opentofu/$(basename ${i})/$(basename ${f})

# We normalize the JSON output to make them comparable regardless of key order
diff \
$(realpath $(dirname $0))/results/terraform/$(basename ${i})/$(basename ${f}) \
$(realpath $(dirname $0))/results/opentofu/$(basename ${i})/$(basename ${f}) \
<(cat $terraform_file | jq -reM '""' 2>/dev/null || cat $terraform_file) \
<(cat $terraform_file | jq -reM '""' 2>/dev/null || cat $opentofu_file) \
|| print_style "FAILED\n" "danger" \
&& print_style "PASS\n" "success"
done
Expand Down
2 changes: 1 addition & 1 deletion testing/equivalence/results/opentofu/test_abac_rules/plan
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The behavior may therefore not match any released version of the provider and
applying changes may cause the state to become incompatible with published
releases.
module.test.data.codefresh_team.users: Reading...
module.test.data.codefresh_team.users: Read complete after 0s [id=64050eece8e7a480941d22b2]
module.test.data.codefresh_team.users: Read complete after xs [id=64050eece8e7a480941d22b2]

OpenTofu used the selected providers to generate the following execution plan.
Resource actions are indicated with the following symbols:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

Warning: Provider development overrides are in effect

The following provider development overrides are set in the CLI
configuration:
- codefresh-io/codefresh in /Users/yonatankoren/software/codefresh-io/tofu-provider-codefresh

The behavior may therefore not match any released version of the provider and
applying changes may cause the state to become incompatible with published
releases.

OpenTofu used the selected providers to generate the following execution plan.
Resource actions are indicated with the following symbols:
+ create

OpenTofu will perform the following actions:

# module.test.codefresh_account_user_association.admin will be created
+ resource "codefresh_account_user_association" "admin" {
+ admin = true
+ email = "[email protected]"
+ id = (known after apply)
+ status = (known after apply)
+ username = (known after apply)
}

# module.test.codefresh_account_user_association.user will be created
+ resource "codefresh_account_user_association" "user" {
+ admin = false
+ email = "[email protected]"
+ id = (known after apply)
+ status = (known after apply)
+ username = (known after apply)
}

Plan: 2 to add, 0 to change, 0 to destroy.

─────────────────────────────────────────────────────────────────────────────

Saved the plan to: equivalence_test_plan

To perform exactly these actions, run the following command to apply:
tofu apply "equivalence_test_plan"
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"configuration": {
"provider_config": {
"module.test:codefresh": {
"full_name": "registry.terraform.io/codefresh-io/codefresh",
"module_address": "module.test",
"name": "codefresh"
}
},
"root_module": {
"module_calls": {
"test": {
"module": {
"resources": [
{
"address": "codefresh_account_user_association.admin",
"expressions": {
"admin": {
"constant_value": true
},
"email": {
"constant_value": "[email protected]"
}
},
"mode": "managed",
"name": "admin",
"provider_config_key": "module.test:codefresh",
"schema_version": 0,
"type": "codefresh_account_user_association"
},
{
"address": "codefresh_account_user_association.user",
"expressions": {
"email": {
"constant_value": "[email protected]"
}
},
"mode": "managed",
"name": "user",
"provider_config_key": "module.test:codefresh",
"schema_version": 0,
"type": "codefresh_account_user_association"
}
]
},
"source": "../../../../examples/account_user_associations"
}
}
}
},
"format_version": "1.2",
"planned_values": {
"root_module": {
"child_modules": [
{
"address": "module.test",
"resources": [
{
"address": "module.test.codefresh_account_user_association.admin",
"mode": "managed",
"name": "admin",
"provider_name": "registry.terraform.io/codefresh-io/codefresh",
"schema_version": 0,
"sensitive_values": {},
"type": "codefresh_account_user_association",
"values": {
"admin": true,
"email": "[email protected]"
}
},
{
"address": "module.test.codefresh_account_user_association.user",
"mode": "managed",
"name": "user",
"provider_name": "registry.terraform.io/codefresh-io/codefresh",
"schema_version": 0,
"sensitive_values": {},
"type": "codefresh_account_user_association",
"values": {
"admin": false,
"email": "[email protected]"
}
}
]
}
]
}
},
"resource_changes": [
{
"address": "module.test.codefresh_account_user_association.admin",
"change": {
"actions": [
"create"
],
"after": {
"admin": true,
"email": "[email protected]"
},
"after_sensitive": {},
"after_unknown": {
"id": true,
"status": true,
"username": true
},
"before": null,
"before_sensitive": false
},
"mode": "managed",
"module_address": "module.test",
"name": "admin",
"provider_name": "registry.terraform.io/codefresh-io/codefresh",
"type": "codefresh_account_user_association"
},
{
"address": "module.test.codefresh_account_user_association.user",
"change": {
"actions": [
"create"
],
"after": {
"admin": false,
"email": "[email protected]"
},
"after_sensitive": {},
"after_unknown": {
"id": true,
"status": true,
"username": true
},
"before": null,
"before_sensitive": false
},
"mode": "managed",
"module_address": "module.test",
"name": "user",
"provider_name": "registry.terraform.io/codefresh-io/codefresh",
"type": "codefresh_account_user_association"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
No state.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"format_version": "1.0"
}
Loading

0 comments on commit 6743d68

Please sign in to comment.