mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-02 04:07:22 -06:00
179aa62ad4
Previously we only validated that the cloudflare record provided was a valid record type. However, a record can be of a valid type, and still not be proxied, making it an invalid record type. The main downside to having to check for whether or not the record type is proxied or not during validation, is that it relies on having two schema keys populated. This means that we can only catch the improper record type during `apply` time, instead of `plan` time. ``` $ go test -v -run "TestValidateRecordType" ./builtin/providers/cloudflare === RUN TestValidateRecordType --- PASS: TestValidateRecordType (0.00s) PASS ok github.com/hashicorp/terraform/builtin/providers/cloudflare 0.004s ```
64 lines
1.3 KiB
Go
64 lines
1.3 KiB
Go
package cloudflare
|
|
|
|
import "testing"
|
|
|
|
func TestValidateRecordType(t *testing.T) {
|
|
validTypes := map[string]bool{
|
|
"A": true,
|
|
"AAAA": true,
|
|
"CNAME": true,
|
|
"TXT": false,
|
|
"SRV": false,
|
|
"LOC": false,
|
|
"MX": false,
|
|
"NS": false,
|
|
"SPF": false,
|
|
}
|
|
for k, v := range validTypes {
|
|
err := validateRecordType(k, v)
|
|
if err != nil {
|
|
t.Fatalf("%s should be a valid record type: %s", k, err)
|
|
}
|
|
}
|
|
|
|
invalidTypes := map[string]bool{
|
|
"a": false,
|
|
"cName": false,
|
|
"txt": false,
|
|
"SRv": false,
|
|
"foo": false,
|
|
"bar": false,
|
|
"TXT": true,
|
|
"SRV": true,
|
|
"SPF": true,
|
|
}
|
|
for k, v := range invalidTypes {
|
|
if err := validateRecordType(k, v); err == nil {
|
|
t.Fatalf("%s should be an invalid record type", k)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestValidateRecordName(t *testing.T) {
|
|
validNames := map[string]string{
|
|
"A": "192.168.0.1",
|
|
"AAAA": "2001:0db8:0000:0042:0000:8a2e:0370:7334",
|
|
}
|
|
|
|
for k, v := range validNames {
|
|
if err := validateRecordName(k, v); err != nil {
|
|
t.Fatalf("%q should be a valid name for type %q: %v", v, k, err)
|
|
}
|
|
}
|
|
|
|
invalidNames := map[string]string{
|
|
"A": "terraform.io",
|
|
"AAAA": "192.168.0.1",
|
|
}
|
|
for k, v := range invalidNames {
|
|
if err := validateRecordName(k, v); err == nil {
|
|
t.Fatalf("%q should be an invalid name for type %q", v, k)
|
|
}
|
|
}
|
|
}
|