From b979053361a882c8b2c8ebf67928440eea6ca38a Mon Sep 17 00:00:00 2001 From: Kristin Laemmert Date: Tue, 29 May 2018 10:05:58 -0700 Subject: [PATCH] general cleanup - addressing code review --- lang/funcs/collection.go | 8 +++----- lang/funcs/collection_test.go | 13 ++++++++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lang/funcs/collection.go b/lang/funcs/collection.go index 38d7269ce..63a08e5ec 100644 --- a/lang/funcs/collection.go +++ b/lang/funcs/collection.go @@ -264,10 +264,6 @@ var DistinctFunc = function.New(&function.Spec{ }, Type: function.StaticReturnType(cty.List(cty.DynamicPseudoType)), Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { - if len(args) != 1 { - return cty.NilVal, fmt.Errorf("distinct accepts only one argument") - } - var list []cty.Value for it := args[0].ElementIterator(); it.Next(); { @@ -295,7 +291,9 @@ var ChunklistFunc = function.New(&function.Spec{ Type: cty.Number, }, }, - Type: function.StaticReturnType(cty.List(cty.DynamicPseudoType)), + Type: func(args []cty.Value) (cty.Type, error) { + return cty.List(args[0].Type()), nil + }, Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { var size int err = gocty.FromCtyValue(args[1], &size) diff --git a/lang/funcs/collection_test.go b/lang/funcs/collection_test.go index 5796f1e5f..dbab50d35 100644 --- a/lang/funcs/collection_test.go +++ b/lang/funcs/collection_test.go @@ -459,6 +459,17 @@ func TestContains(t *testing.T) { cty.BoolVal(false), false, }, + { // Check a list with an unknown value + cty.ListVal([]cty.Value{ + cty.UnknownVal(cty.String), + cty.StringVal("quick"), + cty.StringVal("brown"), + cty.StringVal("fox"), + }), + cty.StringVal("quick"), + cty.BoolVal(true), + false, + }, } for _, test := range tests { @@ -474,7 +485,7 @@ func TestContains(t *testing.T) { t.Fatalf("unexpected error: %s", err) } - if got != test.Want { + if !got.RawEquals(test.Want) { t.Errorf("wrong result\ngot: %#v\nwant: %#v", got, test.Want) } })