|
|
|
|
@ -658,7 +658,7 @@ func TestValidateDurationBetween(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestValidateStringURL(t *testing.T) {
|
|
|
|
|
func TestValidateStringLegacyURL(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
path := cty.GetAttrPath("field")
|
|
|
|
|
@ -694,44 +694,28 @@ func TestValidateStringURL(t *testing.T) {
|
|
|
|
|
"no scheme no trailing slash": {
|
|
|
|
|
val: "domain.test",
|
|
|
|
|
expected: tfdiags.Diagnostics{
|
|
|
|
|
attributeErrDiag(
|
|
|
|
|
"Invalid Value",
|
|
|
|
|
fmt.Sprintf("The value must be a valid URL containing at least a scheme and hostname. Had %q", "domain.test"),
|
|
|
|
|
path,
|
|
|
|
|
),
|
|
|
|
|
legacyIncompleteURLDiag("domain.test", path),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"no scheme no path": {
|
|
|
|
|
val: "domain.test/",
|
|
|
|
|
expected: tfdiags.Diagnostics{
|
|
|
|
|
attributeErrDiag(
|
|
|
|
|
"Invalid Value",
|
|
|
|
|
fmt.Sprintf("The value must be a valid URL containing at least a scheme and hostname. Had %q", "domain.test/"),
|
|
|
|
|
path,
|
|
|
|
|
),
|
|
|
|
|
legacyIncompleteURLDiag("domain.test/", path),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"no scheme with path": {
|
|
|
|
|
val: "domain.test/path",
|
|
|
|
|
expected: tfdiags.Diagnostics{
|
|
|
|
|
attributeErrDiag(
|
|
|
|
|
"Invalid Value",
|
|
|
|
|
fmt.Sprintf("The value must be a valid URL containing at least a scheme and hostname. Had %q", "domain.test/path"),
|
|
|
|
|
path,
|
|
|
|
|
),
|
|
|
|
|
legacyIncompleteURLDiag("domain.test/path", path),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"no scheme with port": {
|
|
|
|
|
val: "domain.test:1234",
|
|
|
|
|
expected: tfdiags.Diagnostics{
|
|
|
|
|
attributeErrDiag(
|
|
|
|
|
"Invalid Value",
|
|
|
|
|
fmt.Sprintf("The value must be a valid URL containing at least a scheme and hostname. Had %q", "domain.test:1234"),
|
|
|
|
|
path,
|
|
|
|
|
),
|
|
|
|
|
legacyIncompleteURLDiag("domain.test:1234", path),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
@ -742,14 +726,90 @@ func TestValidateStringURL(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
var diags tfdiags.Diagnostics
|
|
|
|
|
validateStringURL(testcase.val, path, &diags)
|
|
|
|
|
validateStringLegacyURL(testcase.val, path, &diags)
|
|
|
|
|
|
|
|
|
|
if diff := cmp.Diff(diags, testcase.expected, cmp.Comparer(diagnosticComparer)); diff != "" {
|
|
|
|
|
t.Errorf("unexpected diagnostics difference: %s", diff)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestValidateStringValidURL(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
path := cty.GetAttrPath("field")
|
|
|
|
|
|
|
|
|
|
testcases := map[string]struct {
|
|
|
|
|
val string
|
|
|
|
|
expected tfdiags.Diagnostics
|
|
|
|
|
}{
|
|
|
|
|
"no trailing slash": {
|
|
|
|
|
val: "https://domain.test",
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"no path": {
|
|
|
|
|
val: "https://domain.test/",
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"with path": {
|
|
|
|
|
val: "https://domain.test/path",
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"with port no trailing slash": {
|
|
|
|
|
val: "https://domain.test:1234",
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"with port no path": {
|
|
|
|
|
val: "https://domain.test:1234/",
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"with port with path": {
|
|
|
|
|
val: "https://domain.test:1234/path",
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"no scheme no trailing slash": {
|
|
|
|
|
val: "domain.test",
|
|
|
|
|
expected: tfdiags.Diagnostics{
|
|
|
|
|
invalidURLDiag("domain.test", path),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"no scheme no path": {
|
|
|
|
|
val: "domain.test/",
|
|
|
|
|
expected: tfdiags.Diagnostics{
|
|
|
|
|
invalidURLDiag("domain.test/", path),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"no scheme with path": {
|
|
|
|
|
val: "domain.test/path",
|
|
|
|
|
expected: tfdiags.Diagnostics{
|
|
|
|
|
invalidURLDiag("domain.test/path", path),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"no scheme with port": {
|
|
|
|
|
val: "domain.test:1234",
|
|
|
|
|
expected: tfdiags.Diagnostics{
|
|
|
|
|
invalidURLDiag("domain.test:1234", path),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for name, testcase := range testcases {
|
|
|
|
|
testcase := testcase
|
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
|
|
var diags tfdiags.Diagnostics
|
|
|
|
|
validateStringValidURL(testcase.val, path, &diags)
|
|
|
|
|
|
|
|
|
|
if diff := cmp.Diff(diags, testcase.expected, cmp.Comparer(diagnosticComparer)); diff != "" {
|
|
|
|
|
t.Errorf("unexpected diagnostics difference: %s", diff)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_validateStringDoesNotContain(t *testing.T) {
|
|
|
|
|
|