Skip to content

Commit

Permalink
backport examples and tests for compare_list data source
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuchard committed Feb 25, 2025
1 parent 7efdea9 commit a63a09e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
9 changes: 8 additions & 1 deletion examples/data-sources/stdlib_compare_list/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ data "stdlib_compare_list" "equals" {
# Returns a comparison between two lists.
data "stdlib_compare_list" "greater" {
list_one = ["super", "hyper", "turbo"]
list_two = ["pizza", "cake"]
list_two = ["pizza", "cake", "punch]
}
# result => 1
# Returns a comparison between two lists.
data "stdlib_compare_list" "greater" {
list_one = ["pizza", "cake", "punch]
list_two = ["pizza", "cake"]
}
# result => 1
20 changes: 18 additions & 2 deletions stdlib/slice/compare_list_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,35 @@ func TestAccCompareList(test *testing.T) {
{
Config: `data "stdlib_compare_list" "test" {
list_one = ["super", "hyper", "turbo"]
list_two = ["pizza", "cake"]
list_two = ["pizza", "cake", "punch"]
}`,
Check: resource.ComposeAggregateTestCheckFunc(
// verify input params are stored correctly
resource.TestCheckResourceAttr("data.stdlib_compare_list.test", "list_one.#", "3"),
resource.TestCheckResourceAttr("data.stdlib_compare_list.test", "list_one.2", "turbo"),
resource.TestCheckResourceAttr("data.stdlib_compare_list.test", "list_two.#", "2"),
resource.TestCheckResourceAttr("data.stdlib_compare_list.test", "list_two.#", "3"),
resource.TestCheckResourceAttr("data.stdlib_compare_list.test", "list_two.1", "cake"),
// verify list comparison result is stored correctly
resource.TestCheckResourceAttr("data.stdlib_compare_list.test", "id", "superpizza"),
resource.TestCheckResourceAttr("data.stdlib_compare_list.test", "result", "1"),
),
},
{
Config: `data "stdlib_compare_list" "test" {
list_one = ["pizza", "cake", "punch]
list_two = ["pizza", "cake"]
}`,
Check: resource.ComposeAggregateTestCheckFunc(
// verify input params are stored correctly
resource.TestCheckResourceAttr("data.stdlib_compare_list.test", "list_one.#", "3"),
resource.TestCheckResourceAttr("data.stdlib_compare_list.test", "list_one.0", "pizza"),
resource.TestCheckResourceAttr("data.stdlib_compare_list.test", "list_two.#", "2"),
resource.TestCheckResourceAttr("data.stdlib_compare_list.test", "list_two.1", "cake"),
// verify list comparison result is stored correctly
resource.TestCheckResourceAttr("data.stdlib_compare_list.test", "id", "pizzapizza"),
resource.TestCheckResourceAttr("data.stdlib_compare_list.test", "result", "1"),
),
},
},
})
}
2 changes: 1 addition & 1 deletion stdlib/slice/compare_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
slicefunc "github.com/mschuchard/terraform-provider-stdlib/stdlib/slice"
)

func TestCutFunction(test *testing.T) {
func TestCompareListFunction(test *testing.T) {
test.Parallel()

standardTestCases := map[string]struct {
Expand Down
12 changes: 8 additions & 4 deletions stdlib/string/cut_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ func TestCutFunction(test *testing.T) {
expected: function.RunResponse{
Result: function.NewResultData(types.TupleValueMust(
[]attr.Type{types.StringType, types.StringType, types.BoolType},
[]attr.Value{types.StringValue("foo"), types.StringValue("baz"), types.BoolValue(true)})),
[]attr.Value{types.StringValue("foo"), types.StringValue("baz"), types.BoolValue(true)},
)),
},
},
"separator-absent": {
Expand All @@ -35,7 +36,8 @@ func TestCutFunction(test *testing.T) {
expected: function.RunResponse{
Result: function.NewResultData(types.TupleValueMust(
[]attr.Type{types.StringType, types.StringType, types.BoolType},
[]attr.Value{types.StringValue("foobarbaz"), types.StringValue(""), types.BoolValue(false)})),
[]attr.Value{types.StringValue("foobarbaz"), types.StringValue(""), types.BoolValue(false)},
)),
},
},
"empty-string": {
Expand All @@ -45,7 +47,8 @@ func TestCutFunction(test *testing.T) {
expected: function.RunResponse{
Error: function.NewArgumentFuncError(0, "cut: input string parameter must be at least length 1"),
Result: function.NewResultData(types.TupleUnknown(
[]attr.Type{types.StringType, types.StringType, types.BoolType})),
[]attr.Type{types.StringType, types.StringType, types.BoolType},
)),
},
},
"empty-separator": {
Expand All @@ -55,7 +58,8 @@ func TestCutFunction(test *testing.T) {
expected: function.RunResponse{
Error: function.NewArgumentFuncError(1, "cut: separator parameter must be at least length 1"),
Result: function.NewResultData(types.TupleUnknown(
[]attr.Type{types.StringType, types.StringType, types.BoolType})),
[]attr.Type{types.StringType, types.StringType, types.BoolType},
)),
},
},
}
Expand Down

0 comments on commit a63a09e

Please sign in to comment.