func TestCertsList(t *testing.T) { t.Parallel() expected := []api.Cert{ api.Cert{ Name: "test.example.com", Expires: "2014-01-01T00:00:00UTC", }, } handler := fakeHTTPServer{} server := httptest.NewServer(handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"} actual, err := List(&client) if err != nil { t.Fatal(err) } if !reflect.DeepEqual(expected, actual) { t.Errorf("Expected %v, Got %v", expected, actual) } }
func TestAppsRun(t *testing.T) { t.Parallel() expected := api.AppRunResponse{ Output: "hi\n", ReturnCode: 0, } handler := fakeHTTPServer{} server := httptest.NewServer(&handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"} actual, err := Run(&client, "example-go", "echo hi") if err != nil { t.Fatal(err) } if !reflect.DeepEqual(expected, actual) { t.Errorf("Expected %v, Got %v", expected, actual) } }
func TestListAdmins(t *testing.T) { t.Parallel() expected := []string{ "test", "foo", } handler := fakeHTTPServer{} server := httptest.NewServer(handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"} actual, err := ListAdmins(&client) if err != nil { t.Fatal(err) } if !reflect.DeepEqual(expected, actual) { t.Errorf("Expected %v, Got %v", expected, actual) } }
func TestRollbacker(t *testing.T) { t.Parallel() expected := 7 handler := fakeHTTPServer{} server := httptest.NewServer(handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"} actual, err := Rollback(&client, "rollbacker", -1) if err != nil { t.Fatal(err) } if expected != actual { t.Error(fmt.Errorf("Expected %v, Got %v", expected, actual)) } }
func TestDomainsAdd(t *testing.T) { t.Parallel() expected := api.Domain{ App: "example-go", Created: "2014-01-01T00:00:00UTC", Domain: "example.example.com", Owner: "test", Updated: "2014-01-01T00:00:00UTC", } handler := fakeHTTPServer{} server := httptest.NewServer(handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"} actual, err := New(&client, "example-go", "example.example.com") if err != nil { t.Fatal(err) } if !reflect.DeepEqual(expected, actual) { t.Error(fmt.Errorf("Expected %v, Got %v", expected, actual)) } }
// Login to a Deis controller. func Login(controller string, username string, password string, sslVerify bool) error { u, err := url.Parse(controller) if err != nil { return err } controllerURL, err := chooseScheme(*u) if err != nil { return err } if err = client.CheckConection(client.CreateHTTPClient(sslVerify), controllerURL); err != nil { return err } if username == "" { fmt.Print("username: "******"" { fmt.Print("password: ") password, err = readPassword() fmt.Println() if err != nil { return err } } return client.Login(controllerURL, username, password, sslVerify) }
func TestLogin(t *testing.T) { t.Parallel() handler := fakeHTTPServer{} server := httptest.NewServer(&handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u} actual, err := Login(&client, "test", "opensesame") if err != nil { t.Error(err) } expected := "abc" if actual != expected { t.Errorf("Expected %s, Got %s", expected, actual) } }
func TestConfigUnset(t *testing.T) { t.Parallel() handler := fakeHTTPServer{} server := httptest.NewServer(&handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"} expected := api.Config{ Owner: "test", App: "unset-test", Values: map[string]interface{}{}, Memory: map[string]interface{}{}, CPU: map[string]interface{}{}, Tags: map[string]interface{}{}, Created: "2014-01-01T00:00:00UTC", Updated: "2014-01-01T00:00:00UTC", UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75", } configVars := api.Config{ Values: map[string]interface{}{ "TEST": nil, "FOO": nil, }, Memory: map[string]interface{}{ "web": nil, }, CPU: map[string]interface{}{ "web": nil, }, Tags: map[string]interface{}{ "test": nil, }, } actual, err := Set(&client, "unset-test", configVars) if err != nil { t.Error(err) } if !reflect.DeepEqual(expected, actual) { t.Errorf("Expected %v, Got %v", expected, actual) } }
func TestRegenerate(t *testing.T) { t.Parallel() handler := fakeHTTPServer{} server := httptest.NewServer(&handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u} token, err := Regenerate(&client, "", true) if err != nil { t.Error(err) } if token != "" { t.Errorf("Expected token be empty, Got %s", token) } token, err = Regenerate(&client, "test", false) if err != nil { t.Error(err) } expected := "123" if token != expected { t.Errorf("Expected %s, Got %s", expected, token) } token, err = Regenerate(&client, "", false) if err != nil { t.Error(err) } expected = "abc" if token != expected { t.Errorf("Expected %s, Got %s", expected, token) } }
// Register creates a account on a Deis controller. func Register(controller string, username string, password string, email string, sslVerify bool) error { u, err := url.Parse(controller) if err != nil { return err } controllerURL, err := chooseScheme(*u) if err != nil { return err } if err = client.CheckConection(client.CreateHTTPClient(sslVerify), controllerURL); err != nil { return err } if username == "" { fmt.Print("username: "******"" { fmt.Print("password: "******"\npassword (confirm): ") passwordConfirm, err := readPassword() fmt.Println() if err != nil { return err } if password != passwordConfirm { return errors.New("Password mismatch, aborting registration.") } } if email == "" { fmt.Print("email: ") fmt.Scanln(&email) } return client.Register(controllerURL, username, password, email, sslVerify, true) }
func TestBuildsList(t *testing.T) { t.Parallel() expected := []api.Build{ api.Build{ App: "example-go", Created: "2014-01-01T00:00:00UTC", Dockerfile: "FROM deis/slugrunner RUN mkdir -p /app WORKDIR /app ENTRYPOINT [\"/runner/init\"] ADD slug.tgz /app ENV GIT_SHA 060da68f654e75fac06dbedd1995d5f8ad9084db", Image: "example-go", Owner: "test", Procfile: map[string]string{ "web": "example-go", }, Sha: "060da68f", Updated: "2014-01-01T00:00:00UTC", UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75", }, } handler := fakeHTTPServer{} server := httptest.NewServer(handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"} actual, err := List(&client, "example-go") if err != nil { t.Fatal(err) } if !reflect.DeepEqual(expected, actual) { t.Error(fmt.Errorf("Expected %v, Got %v", expected, actual)) } }
func TestBuildCreate(t *testing.T) { t.Parallel() expected := api.Build{ App: "example-go", Created: "2014-01-01T00:00:00UTC", Image: "deis/example-go:latest", Owner: "test", Procfile: map[string]string{ "web": "example-go", }, Updated: "2014-01-01T00:00:00UTC", UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75", } handler := fakeHTTPServer{} server := httptest.NewServer(handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"} procfile := map[string]string{ "web": "example-go", } actual, err := New(&client, "example-go", "deis/example-go", procfile) if err != nil { t.Fatal(err) } if !reflect.DeepEqual(expected, actual) { t.Error(fmt.Errorf("Expected %v, Got %v", expected, actual)) } }
func TestUsersList(t *testing.T) { t.Parallel() expected := []api.User{ api.User{ ID: 1, LastLogin: "******", IsSuperuser: true, Username: "******", FirstName: "test", LastName: "testerson", Email: "*****@*****.**", IsStaff: true, IsActive: true, DateJoined: "2014-10-19T22:01:00.601Z", }, } handler := fakeHTTPServer{} server := httptest.NewServer(handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"} actual, err := List(&client) if err != nil { t.Fatal(err) } if !reflect.DeepEqual(expected, actual) { t.Errorf("Expected %v, Got %v", expected, actual) } }
func TestDelete(t *testing.T) { t.Parallel() handler := fakeHTTPServer{} server := httptest.NewServer(&handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u} if err := Delete(&client); err != nil { t.Error(err) } }
func TestProcessesList(t *testing.T) { t.Parallel() expected := []api.Process{ api.Process{ Owner: "test", App: "example-go", Release: "v2", Created: "2014-01-01T00:00:00UTC", Updated: "2014-01-01T00:00:00UTC", UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75", Type: "web", Num: 1, State: "up", }, } handler := fakeHTTPServer{} server := httptest.NewServer(handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"} actual, _, err := List(&client, "example-go", 100) if err != nil { t.Fatal(err) } if !reflect.DeepEqual(expected, actual) { t.Error(fmt.Errorf("Expected %v, Got %v", expected, actual)) } }
func TestReleasesList(t *testing.T) { t.Parallel() expected := []api.Release{ api.Release{ App: "example-go", Build: "", Config: "95bd6dea-1685-4f78-a03d-fd7270b058d1", Created: "2014-01-01T00:00:00UTC", Owner: "test", Summary: "test created initial release", Updated: "2014-01-01T00:00:00UTC", UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75", Version: 1, }, } handler := fakeHTTPServer{} server := httptest.NewServer(handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"} actual, err := List(&client, "example-go") if err != nil { t.Fatal(err) } if !reflect.DeepEqual(expected, actual) { t.Error(fmt.Errorf("Expected %v, Got %v", expected, actual)) } }
func TestDomainsRemove(t *testing.T) { t.Parallel() handler := fakeHTTPServer{} server := httptest.NewServer(handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"} if err = Delete(&client, "example-go", "test.com"); err != nil { t.Fatal(err) } }
func TestScale(t *testing.T) { t.Parallel() handler := fakeHTTPServer{} server := httptest.NewServer(&handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"} if err = Scale(&client, "example-go", map[string]int{"web": 2}); err != nil { t.Fatal(err) } }
func TestNewAdmin(t *testing.T) { t.Parallel() handler := fakeHTTPServer{} server := httptest.NewServer(handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"} if err = NewAdmin(&client, "test"); err != nil { t.Fatal(err) } }
func TestRegister(t *testing.T) { t.Parallel() handler := fakeHTTPServer{} server := httptest.NewServer(&handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u} if err = Register(&client, "test", "opensesame", "*****@*****.**"); err != nil { t.Error(err) } }
func TestAppsLogs(t *testing.T) { t.Parallel() tests := []testExpected{ testExpected{ Input: -1, Expected: "test\nfoo\nbar\n", }, testExpected{ Input: 1, Expected: "test\n", }, } handler := fakeHTTPServer{} server := httptest.NewServer(&handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"} for _, test := range tests { actual, err := Logs(&client, "example-go", test.Input) if err != nil { t.Error(err) } if actual != test.Expected { t.Errorf("Expected %s, Got %s", test.Expected, actual) } } }
func TestKeysList(t *testing.T) { t.Parallel() expected := []api.Key{ api.Key{ Created: "2014-01-01T00:00:00UTC", ID: "*****@*****.**", Owner: "test", Public: "ssh-rsa abc [email protected]", Updated: "2014-01-01T00:00:00UTC", UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75", }, } handler := fakeHTTPServer{} server := httptest.NewServer(handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"} actual, _, err := List(&client, 100) if err != nil { t.Fatal(err) } if !reflect.DeepEqual(expected, actual) { t.Errorf("Expected %v, Got %v", expected, actual) } }
func TestAppsCreate(t *testing.T) { t.Parallel() expected := api.App{ ID: "example-go", Created: "2014-01-01T00:00:00UTC", Owner: "test", Updated: "2014-01-01T00:00:00UTC", URL: "example-go.example.com", UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75", } handler := fakeHTTPServer{createID: false, createWithoutID: false} server := httptest.NewServer(&handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"} for _, id := range []string{"example-go", ""} { actual, err := New(&client, id) if err != nil { t.Fatal(err) } if !reflect.DeepEqual(expected, actual) { t.Errorf("Expected %v, Got %v", expected, actual) } } }
// Login to a Deis controller. func Login(controller string, username string, password string, sslVerify bool) error { u, err := url.Parse(controller) if err != nil { return err } controllerURL, err := chooseScheme(*u) httpClient := client.CreateHTTPClient(sslVerify) if err != nil { return err } if err = client.CheckConection(httpClient, controllerURL); err != nil { return err } if username == "" { fmt.Print("username: "******"" { fmt.Print("password: ") password, err = readPassword() fmt.Println() if err != nil { return err } } c := &client.Client{ControllerURL: controllerURL, SSLVerify: sslVerify, HTTPClient: httpClient} return doLogin(c, username, password) }
func TestAppsRestart(t *testing.T) { t.Parallel() tests := []testExpected{ testExpected{ Num: -1, Type: "", Expected: []api.Process{ api.Process{ Owner: "test", App: "example-go", Release: "v2", Created: "2014-01-01T00:00:00UTC", Updated: "2014-01-01T00:00:00UTC", UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75", Type: "web", Num: 1, State: "up", }, }, }, testExpected{ Num: -1, Type: "worker", Expected: []api.Process{ api.Process{ Owner: "test", App: "example-go", Release: "v2", Created: "2014-01-01T00:00:00UTC", Updated: "2014-01-01T00:00:00UTC", UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75", Type: "worker", Num: 1, State: "up", }, }, }, testExpected{ Num: 2, Type: "web", Expected: []api.Process{ api.Process{ Owner: "test", App: "example-go", Release: "v2", Created: "2014-01-01T00:00:00UTC", Updated: "2014-01-01T00:00:00UTC", UUID: "de1bf5b5-4a72-4f94-a10c-d2a3741cdf75", Type: "web", Num: 2, State: "up", }, }, }, } handler := fakeHTTPServer{} server := httptest.NewServer(&handler) defer server.Close() u, err := url.Parse(server.URL) if err != nil { t.Fatal(err) } httpClient := client.CreateHTTPClient(false) client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"} for _, test := range tests { actual, err := Restart(&client, "example-go", test.Type, test.Num) if err != nil { t.Error(err) } if !reflect.DeepEqual(test.Expected, actual) { t.Error(fmt.Errorf("Expected %v, Got %v", test.Expected, actual)) } } }
// Register creates a account on a Deis controller. func Register(controller string, username string, password string, email string, sslVerify bool) error { u, err := url.Parse(controller) httpClient := client.CreateHTTPClient(sslVerify) if err != nil { return err } controllerURL, err := chooseScheme(*u) if err != nil { return err } if err = client.CheckConection(httpClient, controllerURL); err != nil { return err } if username == "" { fmt.Print("username: "******"" { fmt.Print("password: "******"\npassword (confirm): ") passwordConfirm, err := readPassword() fmt.Println() if err != nil { return err } if password != passwordConfirm { return errors.New("Password mismatch, aborting registration.") } } if email == "" { fmt.Print("email: ") fmt.Scanln(&email) } c := &client.Client{ControllerURL: controllerURL, SSLVerify: sslVerify, HTTPClient: httpClient} tempClient, err := client.New() if err == nil { c.Token = tempClient.Token } err = auth.Register(c, username, password, email) c.Token = "" if err != nil { return err } fmt.Printf("Registered %s\n", username) return doLogin(c, username, password) }