Skip to content

Commit

Permalink
three element list tests
Browse files Browse the repository at this point in the history
  • Loading branch information
VenelinMartinov committed Nov 13, 2024
1 parent b6bc19b commit 6d57a22
Show file tree
Hide file tree
Showing 50 changed files with 2,587 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pkg/pf/tests/diff_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ func TestDetailedDiffList(t *testing.T) {
{"changed empty to null", &[]string{}, nil},
{"element added", &[]string{"value"}, &[]string{"value", "value1"}},
{"element removed", &[]string{"value", "value1"}, &[]string{"value"}},
{"removed front", &[]string{"val1", "val2", "val3"}, &[]string{"val2", "val3"}},
{"removed middle", &[]string{"val1", "val2", "val3"}, &[]string{"val1", "val3"}},
{"removed end", &[]string{"val1", "val2", "val3"}, &[]string{"val1", "val2"}},
{"added front", &[]string{"val2", "val3"}, &[]string{"val1", "val2", "val3"}},
{"added middle", &[]string{"val1", "val3"}, &[]string{"val1", "val2", "val3"}},
{"added end", &[]string{"val1", "val2"}, &[]string{"val1", "val2", "val3"}},
}

type testOutput struct {
Expand Down
7 changes: 3 additions & 4 deletions pkg/pf/tests/diff_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"testing"

rschema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
Expand All @@ -28,11 +27,11 @@ func TestDetailedDiffSet(t *testing.T) {

attributeReplaceSchema := rschema.Schema{
Attributes: map[string]rschema.Attribute{
"key": rschema.ListAttribute{
"key": rschema.SetAttribute{
Optional: true,
ElementType: types.StringType,
PlanModifiers: []planmodifier.List{
listplanmodifier.RequiresReplace(),
PlanModifiers: []planmodifier.Set{
setplanmodifier.RequiresReplace(),
},
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
tfbridgetests.testOutput{
initialValue: &[]string{
"val1",
"val2",
},
changeValue: &[]string{
"val1",
"val2",
"val3",
},
tfOut: `
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place

Terraform will perform the following actions:

# testprovider_test.res will be updated in-place
~ resource "testprovider_test" "res" {
id = "test-id"
~ key = [
# (1 unchanged element hidden)
"val2",
+ "val3",
]
}

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

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
~ testprovider:index/test:Test: (update)
[id=test-id]
[urn=urn:pulumi:test::project::testprovider:index/test:Test::p]
~ keys: [
[0]: "val1"
[1]: "val2"
+ [2]: "val3"
]
Resources:
~ 1 to update
1 unchanged
`,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
tfbridgetests.testOutput{
initialValue: &[]string{
"val2",
"val3",
},
changeValue: &[]string{
"val1",
"val2",
"val3",
},
tfOut: `
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place

Terraform will perform the following actions:

# testprovider_test.res will be updated in-place
~ resource "testprovider_test" "res" {
id = "test-id"
~ key = [
+ "val1",
"val2",
# (1 unchanged element hidden)
]
}

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

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
~ testprovider:index/test:Test: (update)
[id=test-id]
[urn=urn:pulumi:test::project::testprovider:index/test:Test::p]
~ keys: [
~ [0]: "val2" => "val1"
~ [1]: "val3" => "val2"
+ [2]: "val3"
]
Resources:
~ 1 to update
1 unchanged
`,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
tfbridgetests.testOutput{
initialValue: &[]string{
"val1",
"val3",
},
changeValue: &[]string{
"val1",
"val2",
"val3",
},
tfOut: `
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place

Terraform will perform the following actions:

# testprovider_test.res will be updated in-place
~ resource "testprovider_test" "res" {
id = "test-id"
~ key = [
"val1",
+ "val2",
"val3",
]
}

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

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
~ testprovider:index/test:Test: (update)
[id=test-id]
[urn=urn:pulumi:test::project::testprovider:index/test:Test::p]
~ keys: [
[0]: "val1"
~ [1]: "val3" => "val2"
+ [2]: "val3"
]
Resources:
~ 1 to update
1 unchanged
`,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
tfbridgetests.testOutput{
initialValue: &[]string{
"val1",
"val2",
"val3",
},
changeValue: &[]string{
"val1",
"val2",
},
tfOut: `
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place

Terraform will perform the following actions:

# testprovider_test.res will be updated in-place
~ resource "testprovider_test" "res" {
id = "test-id"
~ key = [
# (1 unchanged element hidden)
"val2",
- "val3",
]
}

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

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
~ testprovider:index/test:Test: (update)
[id=test-id]
[urn=urn:pulumi:test::project::testprovider:index/test:Test::p]
~ keys: [
[0]: "val1"
[1]: "val2"
- [2]: "val3"
]
Resources:
~ 1 to update
1 unchanged
`,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
tfbridgetests.testOutput{
initialValue: &[]string{
"val1",
"val2",
"val3",
},
changeValue: &[]string{
"val2",
"val3",
},
tfOut: `
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place

Terraform will perform the following actions:

# testprovider_test.res will be updated in-place
~ resource "testprovider_test" "res" {
id = "test-id"
~ key = [
- "val1",
"val2",
# (1 unchanged element hidden)
]
}

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

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
~ testprovider:index/test:Test: (update)
[id=test-id]
[urn=urn:pulumi:test::project::testprovider:index/test:Test::p]
~ keys: [
~ [0]: "val1" => "val2"
~ [1]: "val2" => "val3"
- [2]: "val3"
]
Resources:
~ 1 to update
1 unchanged
`,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
tfbridgetests.testOutput{
initialValue: &[]string{
"val1",
"val2",
"val3",
},
changeValue: &[]string{
"val1",
"val3",
},
tfOut: `
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
~ update in-place

Terraform will perform the following actions:

# testprovider_test.res will be updated in-place
~ resource "testprovider_test" "res" {
id = "test-id"
~ key = [
"val1",
- "val2",
"val3",
]
}

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

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
~ testprovider:index/test:Test: (update)
[id=test-id]
[urn=urn:pulumi:test::project::testprovider:index/test:Test::p]
~ keys: [
[0]: "val1"
~ [1]: "val2" => "val3"
- [2]: "val3"
]
Resources:
~ 1 to update
1 unchanged
`,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
tfbridgetests.testOutput{
initialValue: &[]string{
"val1",
"val2",
},
changeValue: &[]string{
"val1",
"val2",
"val3",
},
tfOut: `
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
+/- create replacement and then destroy

Terraform will perform the following actions:

# testprovider_test.res must be replaced
+/- resource "testprovider_test" "res" {
~ id = "test-id" -> (known after apply)
~ key = [ # forces replacement
# (1 unchanged element hidden)
"val2",
+ "val3",
]
}

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

`,
pulumiOut: `Previewing update (test):
pulumi:pulumi:Stack: (same)
[urn=urn:pulumi:test::project::pulumi:pulumi:Stack::project-test]
+-testprovider:index/test:Test: (replace)
[id=test-id]
[urn=urn:pulumi:test::project::testprovider:index/test:Test::p]
~ id : "test-id" => output<string>
~ keys: [
[0]: "val1"
[1]: "val2"
+ [2]: "val3"
]
Resources:
+-1 to replace
1 unchanged
`,
}
Loading

0 comments on commit 6d57a22

Please sign in to comment.