diff --git a/datasource/datasource.go b/datasource/datasource.go index fdadd7d..4ccce58 100644 --- a/datasource/datasource.go +++ b/datasource/datasource.go @@ -40,8 +40,7 @@ func dialTimeout(network, addr string) (net.Conn, error) { return c, nil } -// Fetches user-data url with support for -// exponential backoff and maximum retries +// Fetches user-data url with support for exponential backoff and maximum retries func fetchURL(rawurl string) ([]byte, error) { if rawurl == "" { return nil, errors.New("user-data URL is empty. Skipping.") @@ -52,20 +51,17 @@ func fetchURL(rawurl string) ([]byte, error) { return nil, err } - // Unfortunately, url.Parse - // is too generic to throw errors - // if a URL does not have a valid HTTP scheme. - // So we have to do this extra validation + // Unfortunately, url.Parse is too generic to throw errors if a URL does not + // have a valid HTTP scheme. So, we have to do this extra validation 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() - // We need to create our own client in order to - // add timeout support. + // We need to create our own client in order to add timeout support. // 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{ Dial: dialTimeout, } diff --git a/datasource/datasource_test.go b/datasource/datasource_test.go index 85b693a..e18839b 100644 --- a/datasource/datasource_test.go +++ b/datasource/datasource_test.go @@ -17,9 +17,8 @@ var expBackoffTests = []struct { {2, "number of attempts: 2"}, } -// Test exponential backoff -// and that it continues retrying if a 5xx -// response is received +// Test exponential backoff and that it continues retrying if a 5xx response is +// received func TestFetchURLExpBackOff(t *testing.T) { for i, tt := range expBackoffTests { mux := http.NewServeMux() @@ -105,9 +104,9 @@ func TestFetchURLMalformed(t *testing.T) { url string want string }{ - {"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."}, - {"ftp://boo", "user-data URL ftp://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."}, + {"ftp://boo", "user-data URL ftp://boo does not have a valid HTTP scheme. Skipping."}, {"", "user-data URL is empty. Skipping."}, }