-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
azurerm_image - change os_disk property to a list #1443
Changes from 1 commit
d2e7367
9384009
fce51c7
a9d730e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package validate | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"strings" | ||
) | ||
|
||
func UrlIsHttpOrHttps(i interface{}, k string) (_ []string, errors []error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There may have been a precedent here you are following, but traditionally initialisms in Go are capitalized: https://github.com/golang/go/wiki/CodeReviewComments#initialisms
|
||
return UrlWithScheme([]string{"http", "https"})(i, k) | ||
} | ||
|
||
func UrlWithScheme(validSchemes []string) schema.SchemaValidateFunc { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See other comment on initialisms. |
||
return func(i interface{}, k string) (_ []string, errors []error) { | ||
v, ok := i.(string) | ||
if !ok { | ||
errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) | ||
return | ||
} | ||
|
||
if v == "" { | ||
errors = append(errors, fmt.Errorf("expected %q url to not be empty", k)) | ||
return | ||
} | ||
|
||
url, err := url.Parse(v) | ||
if err != nil { | ||
errors = append(errors, fmt.Errorf("%q url is in an invalid format: %q (%+v)", k, v, err)) | ||
return | ||
} | ||
|
||
if url.Host == "" { | ||
errors = append(errors, fmt.Errorf("%q url has no host: %q", k, v)) | ||
return | ||
} | ||
|
||
for _, s := range validSchemes { | ||
if url.Scheme == s { | ||
return //last check so just return | ||
} | ||
} | ||
|
||
errors = append(errors, fmt.Errorf("expected %q url %q to have a schema of: %q", k, v, strings.Join(validSchemes, ","))) | ||
return | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package validate | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestHelper_Validate_UrlIsHttpOrHttps(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would just call this |
||
cases := []struct { | ||
Url string | ||
Errors int | ||
}{ | ||
{ | ||
Url: "", | ||
Errors: 1, | ||
}, | ||
{ | ||
Url: "this is not a url", | ||
Errors: 1, | ||
}, | ||
{ | ||
Url: "www.example.com", | ||
Errors: 1, | ||
}, | ||
{ | ||
Url: "ftp://www.example.com", | ||
Errors: 1, | ||
}, | ||
{ | ||
Url: "http://www.example.com", | ||
Errors: 0, | ||
}, | ||
{ | ||
Url: "https://www.example.com", | ||
Errors: 0, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
_, errors := UrlIsHttpOrHttps(tc.Url, "test") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these cases should be inside a |
||
|
||
if len(errors) != tc.Errors { | ||
t.Fatalf("Expected UrlIsHttpOrHttps to have an error for %q", tc.Url) | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you move this up to the first group of imports?