various code review fixes
This commit is contained in:
parent
6463dd90e9
commit
605e23db6b
|
@ -645,7 +645,6 @@ var MergeFunc = function.New(&function.Spec{
|
||||||
VarParam: &function.Parameter{
|
VarParam: &function.Parameter{
|
||||||
Name: "maps",
|
Name: "maps",
|
||||||
Type: cty.DynamicPseudoType,
|
Type: cty.DynamicPseudoType,
|
||||||
AllowUnknown: true,
|
|
||||||
AllowDynamicType: true,
|
AllowDynamicType: true,
|
||||||
AllowNull: true,
|
AllowNull: true,
|
||||||
},
|
},
|
||||||
|
@ -656,7 +655,7 @@ var MergeFunc = function.New(&function.Spec{
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
|
|
||||||
if !arg.Type().IsObjectType() && !arg.Type().IsMapType() {
|
if !arg.Type().IsObjectType() && !arg.Type().IsMapType() {
|
||||||
return cty.NilVal, fmt.Errorf("arguments must be maps or objects, got %#v", arg.Type())
|
return cty.NilVal, fmt.Errorf("arguments must be maps or objects, got %#v", arg.Type().FriendlyName())
|
||||||
}
|
}
|
||||||
for it := arg.ElementIterator(); it.Next(); {
|
for it := arg.ElementIterator(); it.Next(); {
|
||||||
k, v := it.Element()
|
k, v := it.Element()
|
||||||
|
@ -684,7 +683,9 @@ var SliceFunc = 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 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) {
|
||||||
inputList := args[0]
|
inputList := args[0]
|
||||||
var startIndex, endIndex int
|
var startIndex, endIndex int
|
||||||
|
@ -718,7 +719,7 @@ var SliceFunc = function.New(&function.Spec{
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(outputList) == 0 {
|
if len(outputList) == 0 {
|
||||||
return cty.ListValEmpty(cty.DynamicPseudoType), nil
|
return cty.ListValEmpty(retType.ElementType()), nil
|
||||||
}
|
}
|
||||||
return cty.ListVal(outputList), nil
|
return cty.ListVal(outputList), nil
|
||||||
},
|
},
|
||||||
|
@ -736,14 +737,15 @@ var TransposeFunc = function.New(&function.Spec{
|
||||||
Type: function.StaticReturnType(cty.Map(cty.List(cty.String))),
|
Type: function.StaticReturnType(cty.Map(cty.List(cty.String))),
|
||||||
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) {
|
||||||
inputMap := args[0]
|
inputMap := args[0]
|
||||||
|
if !inputMap.IsWhollyKnown() {
|
||||||
|
return cty.UnknownVal(retType), nil
|
||||||
|
}
|
||||||
|
|
||||||
outputMap := make(map[string]cty.Value)
|
outputMap := make(map[string]cty.Value)
|
||||||
tmpMap := make(map[string][]string)
|
tmpMap := make(map[string][]string)
|
||||||
|
|
||||||
for it := inputMap.ElementIterator(); it.Next(); {
|
for it := inputMap.ElementIterator(); it.Next(); {
|
||||||
inKey, inVal := it.Element()
|
inKey, inVal := it.Element()
|
||||||
if !inVal.Type().IsListType() {
|
|
||||||
return cty.MapValEmpty(cty.List(cty.String)), fmt.Errorf("input must be a map of lists of strings")
|
|
||||||
}
|
|
||||||
for iter := inVal.ElementIterator(); iter.Next(); {
|
for iter := inVal.ElementIterator(); iter.Next(); {
|
||||||
_, val := iter.Element()
|
_, val := iter.Element()
|
||||||
if !val.Type().Equals(cty.String) {
|
if !val.Type().Equals(cty.String) {
|
||||||
|
|
|
@ -1568,7 +1568,7 @@ func TestSlice(t *testing.T) {
|
||||||
listOfStrings,
|
listOfStrings,
|
||||||
cty.NumberIntVal(1),
|
cty.NumberIntVal(1),
|
||||||
cty.NumberIntVal(1),
|
cty.NumberIntVal(1),
|
||||||
cty.ListValEmpty(cty.DynamicPseudoType),
|
cty.ListValEmpty(cty.String),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{ // index out of bounds
|
{ // index out of bounds
|
||||||
|
|
Loading…
Reference in New Issue