style(datastore/fetch): Adjusts comments formatting

This commit is contained in:
Camilo Aguilar 2014-05-15 23:38:50 -04:00
parent ebf134f181
commit fcccfb085f
2 changed files with 11 additions and 16 deletions

View File

@ -40,8 +40,7 @@ func dialTimeout(network, addr string) (net.Conn, error) {
return c, nil return c, nil
} }
// Fetches user-data url with support for // Fetches user-data url with support for exponential backoff and maximum retries
// exponential backoff and maximum retries
func fetchURL(rawurl string) ([]byte, error) { func fetchURL(rawurl string) ([]byte, error) {
if rawurl == "" { if rawurl == "" {
return nil, errors.New("user-data URL is empty. Skipping.") return nil, errors.New("user-data URL is empty. Skipping.")
@ -52,18 +51,15 @@ func fetchURL(rawurl string) ([]byte, error) {
return nil, err return nil, err
} }
// Unfortunately, url.Parse // Unfortunately, url.Parse is too generic to throw errors if a URL does not
// is too generic to throw errors // have a valid HTTP scheme. So, we have to do this extra validation
// if a URL does not have a valid HTTP scheme.
// So we have to do this extra validation
if !strings.HasPrefix(url.Scheme, "http") { if !strings.HasPrefix(url.Scheme, "http") {
return nil, fmt.Errorf("user-data URL %s, does not have a valid HTTP scheme. Skipping.", rawurl) return nil, fmt.Errorf("user-data URL %s does not have a valid HTTP scheme. Skipping.", rawurl)
} }
userdataURL := url.String() userdataURL := url.String()
// We need to create our own client in order to // We need to create our own client in order to add timeout support.
// add timeout support.
// TODO(c4milo) Replace it once Go 1.3 is officially used by CoreOS // TODO(c4milo) Replace it once Go 1.3 is officially used by CoreOS
// More info: https://code.google.com/p/go/source/detail?r=ada6f2d5f99f // More info: https://code.google.com/p/go/source/detail?r=ada6f2d5f99f
transport := &http.Transport{ transport := &http.Transport{

View File

@ -17,9 +17,8 @@ var expBackoffTests = []struct {
{2, "number of attempts: 2"}, {2, "number of attempts: 2"},
} }
// Test exponential backoff // Test exponential backoff and that it continues retrying if a 5xx response is
// and that it continues retrying if a 5xx // received
// response is received
func TestFetchURLExpBackOff(t *testing.T) { func TestFetchURLExpBackOff(t *testing.T) {
for i, tt := range expBackoffTests { for i, tt := range expBackoffTests {
mux := http.NewServeMux() mux := http.NewServeMux()
@ -105,9 +104,9 @@ func TestFetchURLMalformed(t *testing.T) {
url string url string
want string want string
}{ }{
{"boo", "user-data URL boo, does not have a valid HTTP scheme. Skipping."}, {"boo", "user-data URL boo does not have a valid HTTP scheme. Skipping."},
{"mailto://boo", "user-data URL mailto://boo, does not have a valid HTTP scheme. Skipping."}, {"mailto://boo", "user-data URL mailto://boo does not have a valid HTTP scheme. Skipping."},
{"ftp://boo", "user-data URL ftp://boo, does not have a valid HTTP scheme. Skipping."}, {"ftp://boo", "user-data URL ftp://boo does not have a valid HTTP scheme. Skipping."},
{"", "user-data URL is empty. Skipping."}, {"", "user-data URL is empty. Skipping."},
} }