general cleanup - addressing code review

This commit is contained in:
Kristin Laemmert 2018-05-29 10:05:58 -07:00 committed by Martin Atkins
parent 498ffbf77b
commit b979053361
2 changed files with 15 additions and 6 deletions

View File

@ -264,10 +264,6 @@ var DistinctFunc = function.New(&function.Spec{
}, },
Type: function.StaticReturnType(cty.List(cty.DynamicPseudoType)), Type: function.StaticReturnType(cty.List(cty.DynamicPseudoType)),
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { 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 var list []cty.Value
for it := args[0].ElementIterator(); it.Next(); { for it := args[0].ElementIterator(); it.Next(); {
@ -295,7 +291,9 @@ var ChunklistFunc = function.New(&function.Spec{
Type: cty.Number, 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) { Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
var size int var size int
err = gocty.FromCtyValue(args[1], &size) err = gocty.FromCtyValue(args[1], &size)

View File

@ -459,6 +459,17 @@ func TestContains(t *testing.T) {
cty.BoolVal(false), cty.BoolVal(false),
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 { for _, test := range tests {
@ -474,7 +485,7 @@ func TestContains(t *testing.T) {
t.Fatalf("unexpected error: %s", err) 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) t.Errorf("wrong result\ngot: %#v\nwant: %#v", got, test.Want)
} }
}) })