add test cases and remove no-longer-needed validation

This commit is contained in:
Kristin Laemmert 2020-07-08 13:14:15 -04:00
parent 384cfaacf9
commit e639d813ee
2 changed files with 16 additions and 7 deletions

View File

@ -97,10 +97,6 @@ var CidrSubnetFunc = function.New(&function.Spec{
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)
if err != nil {
return cty.UnknownVal(cty.String), err

View File

@ -56,6 +56,12 @@ func TestCidrHost(t *testing.T) {
cty.UnknownVal(cty.String),
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 {
@ -183,21 +189,28 @@ func TestCidrSubnet(t *testing.T) {
cty.StringVal("192.168.0.0/168"),
cty.NumberIntVal(2),
cty.NumberIntVal(16),
cty.StringVal("fe80:0:0:6::/64"),
cty.UnknownVal(cty.String),
true,
},
{ // not a valid CIDR mask
cty.StringVal("not-a-cidr"),
cty.NumberIntVal(4),
cty.NumberIntVal(6),
cty.StringVal("fe80:0:0:6::/64"),
cty.UnknownVal(cty.String),
true,
},
{ // can't have an octet >255
cty.StringVal("10.256.0.0/8"),
cty.NumberIntVal(4),
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,
},
}