style(httpbackoff -> pkg): Adjusts package name to follow convention

This commit is contained in:
Camilo Aguilar 2014-05-22 14:37:19 -04:00
parent 2cedebb4eb
commit 8ca3c2ed1f
9 changed files with 24 additions and 22 deletions

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
*.swp *.swp
bin/ bin/
coverage/ coverage/
pkg/ gopath/

7
build
View File

@ -3,7 +3,12 @@
ORG_PATH="github.com/coreos" ORG_PATH="github.com/coreos"
REPO_PATH="${ORG_PATH}/coreos-cloudinit" REPO_PATH="${ORG_PATH}/coreos-cloudinit"
if [ ! -h gopath/src/${REPO_PATH} ]; then
mkdir -p gopath/src/${ORG_PATH}
ln -s ../../../.. gopath/src/${REPO_PATH} || exit 255
fi
export GOBIN=${PWD}/bin export GOBIN=${PWD}/bin
export GOPATH=${PWD} export GOPATH=${PWD}/gopath
go build -o bin/coreos-cloudinit ${REPO_PATH} go build -o bin/coreos-cloudinit ${REPO_PATH}

View File

@ -1,6 +1,6 @@
package datasource package datasource
import "github.com/coreos/coreos-cloudinit/httpbackoff" import "github.com/coreos/coreos-cloudinit/pkg"
type metadataService struct { type metadataService struct {
url string url string
@ -11,7 +11,7 @@ func NewMetadataService(url string) *metadataService {
} }
func (ms *metadataService) Fetch() ([]byte, error) { func (ms *metadataService) Fetch() ([]byte, error) {
client := httpbackoff.NewHttpClient() client := pkg.NewHttpClient()
return client.Get(ms.url) return client.Get(ms.url)
} }

View File

@ -6,7 +6,7 @@ import (
"log" "log"
"strings" "strings"
"github.com/coreos/coreos-cloudinit/httpbackoff" "github.com/coreos/coreos-cloudinit/pkg"
) )
const ( const (
@ -31,7 +31,7 @@ func (self *procCmdline) Fetch() ([]byte, error) {
return nil, err return nil, err
} }
client := httpbackoff.NewHttpClient() client := pkg.NewHttpClient()
cfg, err := client.Get(url) cfg, err := client.Get(url)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -4,7 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/coreos/coreos-cloudinit/httpbackoff" "github.com/coreos/coreos-cloudinit/pkg"
"github.com/coreos/coreos-cloudinit/system" "github.com/coreos/coreos-cloudinit/system"
) )
@ -24,7 +24,7 @@ func SSHImportKeysFromURL(system_user string, url string) error {
} }
func fetchUserKeys(url string) ([]string, error) { func fetchUserKeys(url string) ([]string, error) {
client := httpbackoff.NewHttpClient() client := pkg.NewHttpClient()
data, err := client.Get(url) data, err := client.Get(url)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -1,4 +1,4 @@
package httpbackoff package pkg
import ( import (
"crypto/tls" "crypto/tls"
@ -23,14 +23,14 @@ type HttpClient struct {
// Maximum exp backoff duration. Defaults to 5 seconds // Maximum exp backoff duration. Defaults to 5 seconds
MaxBackoff time.Duration MaxBackoff time.Duration
// Maximum amount of connection retries. Defaults to 15 // Maximum number of connection retries. Defaults to 15
MaxRetries int MaxRetries int
// HTTP client timeout, this is suggested to be low since exponential // HTTP client timeout, this is suggested to be low since exponential
// backoff will kick off too. Defaults to 2 seconds // backoff will kick off too. Defaults to 2 seconds
Timeout time.Duration Timeout time.Duration
//Whether or not to skip TLS verification. Defaults to false // Whether or not to skip TLS verification. Defaults to false
SkipTLS bool SkipTLS bool
} }
@ -45,10 +45,6 @@ func NewHttpClient() *HttpClient {
// Fetches a given URL with support for exponential backoff and maximum retries // Fetches a given URL with support for exponential backoff and maximum retries
func (h *HttpClient) Get(rawurl string) ([]byte, error) { func (h *HttpClient) Get(rawurl string) ([]byte, error) {
if h == nil {
return nil, nil
}
if rawurl == "" { if rawurl == "" {
return nil, errors.New("URL is empty. Skipping.") return nil, errors.New("URL is empty. Skipping.")
} }
@ -115,6 +111,8 @@ func (h *HttpClient) Get(rawurl string) ([]byte, error) {
duration = h.MaxBackoff duration = h.MaxBackoff
} }
log.Printf("Sleeping for %d seconds", duration)
time.Sleep(duration) time.Sleep(duration)
} }

View File

@ -1,4 +1,4 @@
package httpbackoff package pkg
import ( import (
"fmt" "fmt"
@ -19,7 +19,7 @@ var expBackoffTests = []struct {
// Test exponential backoff and that it continues retrying if a 5xx response is // Test exponential backoff and that it continues retrying if a 5xx response is
// received // received
func TestFetchURLExpBackOff(t *testing.T) { func TestGetURLExpBackOff(t *testing.T) {
client := NewHttpClient() client := NewHttpClient()
for i, tt := range expBackoffTests { for i, tt := range expBackoffTests {
@ -52,7 +52,7 @@ func TestFetchURLExpBackOff(t *testing.T) {
} }
// Test that it stops retrying if a 4xx response comes back // Test that it stops retrying if a 4xx response comes back
func TestFetchURL4xx(t *testing.T) { func TestGetURL4xx(t *testing.T) {
client := NewHttpClient() client := NewHttpClient()
retries := 0 retries := 0
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@ -72,7 +72,7 @@ func TestFetchURL4xx(t *testing.T) {
} }
// Test that it fetches and returns user-data just fine // Test that it fetches and returns user-data just fine
func TestFetchURL2xx(t *testing.T) { func TestGetURL2xx(t *testing.T) {
var cloudcfg = ` var cloudcfg = `
#cloud-config #cloud-config
coreos: coreos:
@ -103,7 +103,7 @@ coreos:
} }
// Test attempt to fetching using malformed URL // Test attempt to fetching using malformed URL
func TestFetchURLMalformed(t *testing.T) { func TestGetMalformedURL(t *testing.T) {
client := NewHttpClient() client := NewHttpClient()
var tests = []struct { var tests = []struct {

View File

@ -1 +0,0 @@
../../../

2
test
View File

@ -13,7 +13,7 @@ COVER=${COVER:-"-cover"}
source ./build source ./build
declare -a TESTPKGS=(initialize system datasource httpbackoff) declare -a TESTPKGS=(initialize system datasource pkg)
if [ -z "$PKG" ]; then if [ -z "$PKG" ]; then
GOFMTPATH="$TESTPKGS coreos-cloudinit.go" GOFMTPATH="$TESTPKGS coreos-cloudinit.go"