From 8d3e35cd8d92d184dc66041c235163cab4953842 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Fri, 15 Nov 2013 01:13:20 +0000 Subject: [PATCH] Split auth tests between unit tests and integration tests --- auth/auth_test.go | 49 ------------------------------- integration/auth_test.go | 63 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 49 deletions(-) create mode 100644 integration/auth_test.go diff --git a/auth/auth_test.go b/auth/auth_test.go index 5dc634a719..5f2d3b85fd 100644 --- a/auth/auth_test.go +++ b/auth/auth_test.go @@ -1,11 +1,8 @@ package auth import ( - "crypto/rand" - "encoding/hex" "io/ioutil" "os" - "strings" "testing" ) @@ -29,52 +26,6 @@ func TestEncodeAuth(t *testing.T) { } } -func TestLogin(t *testing.T) { - os.Setenv("DOCKER_INDEX_URL", "https://indexstaging-docker.dotcloud.com") - defer os.Setenv("DOCKER_INDEX_URL", "") - authConfig := &AuthConfig{Username: "unittester", Password: "surlautrerivejetattendrai", Email: "noise+unittester@dotcloud.com"} - status, err := Login(authConfig, nil) - if err != nil { - t.Fatal(err) - } - if status != "Login Succeeded" { - t.Fatalf("Expected status \"Login Succeeded\", found \"%s\" instead", status) - } -} - -func TestCreateAccount(t *testing.T) { - os.Setenv("DOCKER_INDEX_URL", "https://indexstaging-docker.dotcloud.com") - defer os.Setenv("DOCKER_INDEX_URL", "") - tokenBuffer := make([]byte, 16) - _, err := rand.Read(tokenBuffer) - if err != nil { - t.Fatal(err) - } - token := hex.EncodeToString(tokenBuffer)[:12] - username := "ut" + token - authConfig := &AuthConfig{Username: username, Password: "test42", Email: "docker-ut+" + token + "@example.com"} - status, err := Login(authConfig, nil) - if err != nil { - t.Fatal(err) - } - expectedStatus := "Account created. Please use the confirmation link we sent" + - " to your e-mail to activate it." - if status != expectedStatus { - t.Fatalf("Expected status: \"%s\", found \"%s\" instead.", expectedStatus, status) - } - - status, err = Login(authConfig, nil) - if err == nil { - t.Fatalf("Expected error but found nil instead") - } - - expectedError := "Login: Account is not Active" - - if !strings.Contains(err.Error(), expectedError) { - t.Fatalf("Expected message \"%s\" but found \"%s\" instead", expectedError, err) - } -} - func setupTempConfigFile() (*ConfigFile, error) { root, err := ioutil.TempDir("", "docker-test-auth") if err != nil { diff --git a/integration/auth_test.go b/integration/auth_test.go new file mode 100644 index 0000000000..dfeb9002bf --- /dev/null +++ b/integration/auth_test.go @@ -0,0 +1,63 @@ +package docker + +import ( + "github.com/dotcloud/docker/auth" + "crypto/rand" + "encoding/hex" + "os" + "strings" + "testing" +) + +// FIXME: these tests have an external dependency on a staging index hosted +// on the docker.io infrastructure. That dependency should be removed. +// - Unit tests should have no side-effect dependencies. +// - Integration tests should have side-effects limited to the host environment being tested. + +func TestLogin(t *testing.T) { + os.Setenv("DOCKER_INDEX_URL", "https://indexstaging-docker.dotcloud.com") + defer os.Setenv("DOCKER_INDEX_URL", "") + authConfig := &auth.AuthConfig{Username: "unittester", Password: "surlautrerivejetattendrai", Email: "noise+unittester@dotcloud.com"} + status, err := auth.Login(authConfig, nil) + if err != nil { + t.Fatal(err) + } + if status != "Login Succeeded" { + t.Fatalf("Expected status \"Login Succeeded\", found \"%s\" instead", status) + } +} + + + +func TestCreateAccount(t *testing.T) { + os.Setenv("DOCKER_INDEX_URL", "https://indexstaging-docker.dotcloud.com") + defer os.Setenv("DOCKER_INDEX_URL", "") + tokenBuffer := make([]byte, 16) + _, err := rand.Read(tokenBuffer) + if err != nil { + t.Fatal(err) + } + token := hex.EncodeToString(tokenBuffer)[:12] + username := "ut" + token + authConfig := &auth.AuthConfig{Username: username, Password: "test42", Email: "docker-ut+" + token + "@example.com"} + status, err := auth.Login(authConfig, nil) + if err != nil { + t.Fatal(err) + } + expectedStatus := "Account created. Please use the confirmation link we sent" + + " to your e-mail to activate it." + if status != expectedStatus { + t.Fatalf("Expected status: \"%s\", found \"%s\" instead.", expectedStatus, status) + } + + status, err = auth.Login(authConfig, nil) + if err == nil { + t.Fatalf("Expected error but found nil instead") + } + + expectedError := "Login: Account is not Active" + + if !strings.Contains(err.Error(), expectedError) { + t.Fatalf("Expected message \"%s\" but found \"%s\" instead", expectedError, err) + } +}