From 359f057a16711a6db5f381507f7f1967285e8564 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 1 May 2019 15:29:12 -0400 Subject: [PATCH] allow chunklist to handle unknowns Chunklist should be able to return chunks containing unknown values. --- lang/funcs/collection.go | 2 +- lang/funcs/collection_test.go | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lang/funcs/collection.go b/lang/funcs/collection.go index 3ec505b00..574fcc43d 100644 --- a/lang/funcs/collection.go +++ b/lang/funcs/collection.go @@ -379,7 +379,7 @@ var ChunklistFunc = function.New(&function.Spec{ }, Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { listVal := args[0] - if !listVal.IsWhollyKnown() { + if !listVal.IsKnown() { return cty.UnknownVal(retType), nil } diff --git a/lang/funcs/collection_test.go b/lang/funcs/collection_test.go index e6dbb04fa..970a44f97 100644 --- a/lang/funcs/collection_test.go +++ b/lang/funcs/collection_test.go @@ -993,13 +993,29 @@ func TestChunklist(t *testing.T) { cty.UnknownVal(cty.String), }), cty.NumberIntVal(1), + cty.ListVal([]cty.Value{ + cty.ListVal([]cty.Value{ + cty.StringVal("a"), + }), + cty.ListVal([]cty.Value{ + cty.StringVal("b"), + }), + cty.ListVal([]cty.Value{ + cty.UnknownVal(cty.String), + }), + }), + false, + }, + { + cty.UnknownVal(cty.List(cty.String)), + cty.NumberIntVal(1), cty.UnknownVal(cty.List(cty.List(cty.String))), false, }, } - for _, test := range tests { - t.Run(fmt.Sprintf("chunklist(%#v, %#v)", test.List, test.Size), func(t *testing.T) { + for i, test := range tests { + t.Run(fmt.Sprintf("%d-chunklist(%#v, %#v)", i, test.List, test.Size), func(t *testing.T) { got, err := Chunklist(test.List, test.Size) if test.Err {