add test cases and remove no-longer-needed validation
This commit is contained in:
parent
384cfaacf9
commit
e639d813ee
|
@ -97,10 +97,6 @@ var CidrSubnetFunc = function.New(&function.Spec{
|
||||||
return cty.UnknownVal(cty.String), fmt.Errorf("invalid CIDR expression: %s", err)
|
return cty.UnknownVal(cty.String), fmt.Errorf("invalid CIDR expression: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if newbits > 64 {
|
|
||||||
return cty.UnknownVal(cty.String), fmt.Errorf("may not extend prefix by more than 64 bits")
|
|
||||||
}
|
|
||||||
|
|
||||||
newNetwork, err := cidr.SubnetBig(network, newbits, netnum)
|
newNetwork, err := cidr.SubnetBig(network, newbits, netnum)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cty.UnknownVal(cty.String), err
|
return cty.UnknownVal(cty.String), err
|
||||||
|
|
|
@ -56,6 +56,12 @@ func TestCidrHost(t *testing.T) {
|
||||||
cty.UnknownVal(cty.String),
|
cty.UnknownVal(cty.String),
|
||||||
true, // can't have an octet >255
|
true, // can't have an octet >255
|
||||||
},
|
},
|
||||||
|
{ // fractions are Not Ok
|
||||||
|
cty.StringVal("10.256.0.0/8"),
|
||||||
|
cty.NumberFloatVal(.75),
|
||||||
|
cty.UnknownVal(cty.String),
|
||||||
|
true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
@ -183,21 +189,28 @@ func TestCidrSubnet(t *testing.T) {
|
||||||
cty.StringVal("192.168.0.0/168"),
|
cty.StringVal("192.168.0.0/168"),
|
||||||
cty.NumberIntVal(2),
|
cty.NumberIntVal(2),
|
||||||
cty.NumberIntVal(16),
|
cty.NumberIntVal(16),
|
||||||
cty.StringVal("fe80:0:0:6::/64"),
|
cty.UnknownVal(cty.String),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{ // not a valid CIDR mask
|
{ // not a valid CIDR mask
|
||||||
cty.StringVal("not-a-cidr"),
|
cty.StringVal("not-a-cidr"),
|
||||||
cty.NumberIntVal(4),
|
cty.NumberIntVal(4),
|
||||||
cty.NumberIntVal(6),
|
cty.NumberIntVal(6),
|
||||||
cty.StringVal("fe80:0:0:6::/64"),
|
cty.UnknownVal(cty.String),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{ // can't have an octet >255
|
{ // can't have an octet >255
|
||||||
cty.StringVal("10.256.0.0/8"),
|
cty.StringVal("10.256.0.0/8"),
|
||||||
cty.NumberIntVal(4),
|
cty.NumberIntVal(4),
|
||||||
cty.NumberIntVal(6),
|
cty.NumberIntVal(6),
|
||||||
cty.StringVal("fe80:0:0:6::/64"),
|
cty.UnknownVal(cty.String),
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
{ // fractions are Not Ok
|
||||||
|
cty.StringVal("10.256.0.0/8"),
|
||||||
|
cty.NumberFloatVal(2 / 3),
|
||||||
|
cty.NumberFloatVal(.75),
|
||||||
|
cty.UnknownVal(cty.String),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue