Fix the auth tests and add the offline mode

This commit is contained in:
Guillaume J. Charmes 2013-06-17 11:29:02 -07:00
parent 389db5f598
commit 13e03a6911
1 changed files with 11 additions and 5 deletions

View File

@ -10,8 +10,8 @@ import (
func TestEncodeAuth(t *testing.T) {
newAuthConfig := &AuthConfig{Username: "ken", Password: "test", Email: "test@example.com"}
authStr := EncodeAuth(newAuthConfig)
decAuthConfig, err := DecodeAuth(authStr)
authStr := encodeAuth(newAuthConfig)
decAuthConfig, err := decodeAuth(authStr)
if err != nil {
t.Fatal(err)
}
@ -27,10 +27,13 @@ func TestEncodeAuth(t *testing.T) {
}
func TestLogin(t *testing.T) {
if os.Getenv("OFFLINE") != "" {
t.Skip("Offline mode, skipping.")
}
os.Setenv("DOCKER_INDEX_URL", "https://indexstaging-docker.dotcloud.com")
defer os.Setenv("DOCKER_INDEX_URL", "")
authConfig := NewAuthConfig("unittester", "surlautrerivejetattendrai", "noise+unittester@dotcloud.com", "/tmp")
status, err := Login(authConfig)
status, err := Login(authConfig, false)
if err != nil {
t.Fatal(err)
}
@ -40,6 +43,9 @@ func TestLogin(t *testing.T) {
}
func TestCreateAccount(t *testing.T) {
if os.Getenv("OFFLINE") != "" {
t.Skip("Offline mode, skipping.")
}
os.Setenv("DOCKER_INDEX_URL", "https://indexstaging-docker.dotcloud.com")
defer os.Setenv("DOCKER_INDEX_URL", "")
tokenBuffer := make([]byte, 16)
@ -50,7 +56,7 @@ func TestCreateAccount(t *testing.T) {
token := hex.EncodeToString(tokenBuffer)[:12]
username := "ut" + token
authConfig := NewAuthConfig(username, "test42", "docker-ut+"+token+"@example.com", "/tmp")
status, err := Login(authConfig)
status, err := Login(authConfig, false)
if err != nil {
t.Fatal(err)
}
@ -60,7 +66,7 @@ func TestCreateAccount(t *testing.T) {
t.Fatalf("Expected status: \"%s\", found \"%s\" instead.", expectedStatus, status)
}
status, err = Login(authConfig)
status, err = Login(authConfig, false)
if err == nil {
t.Fatalf("Expected error but found nil instead")
}