func permsCreateAppTest(t *testing.T, params, user *utils.DeisTestConfig) { utils.Execute(t, authLoginCmd, user, false, "") utils.Execute(t, permsCreateAppCmd, user, true, "403 FORBIDDEN") utils.Execute(t, authLoginCmd, params, false, "") utils.Execute(t, permsCreateAppCmd, params, false, "") utils.CheckList(t, permsListAppCmd, params, "test1", false) }
func appsSetup(t *testing.T) *utils.DeisTestConfig { cfg := utils.GetGlobalConfig() cfg.AppName = "appssample" utils.Execute(t, authLoginCmd, cfg, false, "") utils.Execute(t, gitCloneCmd, cfg, false, "") return cfg }
func TestPs(t *testing.T) { params := psSetup(t) psScaleTest(t, params, psScaleCmd) appsOpenTest(t, params) psListTest(t, params, false) psScaleTest(t, params, psRestartCmd) psScaleTest(t, params, psDownScaleCmd) // FIXME if we don't wait here, some of the routers may give us a 502 before // the app is removed from the config. // we wait 7 seconds since confd reloads every 5 seconds time.Sleep(time.Millisecond * 7000) // test for a 503 response utils.CurlWithFail(t, fmt.Sprintf("http://%s.%s", params.AppName, params.Domain), true, "503") utils.AppsDestroyTest(t, params) utils.Execute(t, psScaleCmd, params, true, "404 NOT FOUND") // ensure we can choose our preferred beverage utils.Execute(t, psScaleCmd, params, true, "but first, coffee!") if err := os.Setenv("DEIS_DRINK_OF_CHOICE", "tea"); err != nil { t.Fatal(err) } utils.Execute(t, psScaleCmd, params, true, "but first, tea!") }
func TestGlobal(t *testing.T) { params := utils.GetGlobalConfig() cookieTest(t, params) utils.Execute(t, authRegisterCmd, params, false, "") utils.Execute(t, keysAddCmd, params, false, "") utils.Execute(t, clustersCreateCmd, params, false, "") }
func tagsTest(t *testing.T, cfg *utils.DeisTestConfig, ver int) { configFleetMetadata(t, cfg) utils.Execute(t, tagsListCmd, cfg, false, "No tags defined") utils.Execute(t, tagsSetCmd, cfg, false, "test") utils.Execute(t, tagsListCmd, cfg, false, "test") utils.Execute(t, tagsUnsetCmd, cfg, false, "No tags defined") }
func appsRunTest(t *testing.T, params *utils.DeisTestConfig) { cmd := appsRunCmd if err := utils.Chdir(params.ExampleApp); err != nil { t.Fatal(err) } utils.CheckList(t, cmd, params, "Hello, 世界", false) utils.Execute(t, "apps:run env", params, true, "GIT_SHA") // Fleet/systemd unit files have a limit of 2048 characters per line or else one encounters // problems parsing the unit. To verify long log messages are truncated and do not crash // logspout (see https://github.com/deis/deis/issues/2046) we must issue a (relatively) short // command via `deis apps:run` that produces a LONG, but testable (predictable) log message we // can search for in the output of `deis logs`. // // The strategy for achieving this is to generate 1k random characters, then use that with a // command submitted via `deis apps:run` that will echo those 1k bytes 64x (on a single line). // Such a message is long enough to crash logspout if handled improperly and ALSO gives us a // large, distinct, and predictable string we can search for in the logs to assert success (and // assert that the message didn't crash logspout) WITHOUT ever needing to transmit such an // egregiously long command via `deis apps:run`. largeString := randomString(1024) utils.Execute(t, fmt.Sprintf("apps:run \"printf '%s%%.0s' {1..64}\"", largeString), params, false, largeString) // To assert the long message didn't crash logspout AND made it to the logger, we will search // the logs for a fragment of the long message-- specifically 2x the random string we generated. // This will help us ensure the actual log message made it through and not JUST the log message // that states the command being execured via `deis apps:run`. We want to find the former, not // the latter because the latter is too short a message to have possibly crashed logspout if // mishandled. utils.Execute(t, "logs", params, false, strings.Repeat(largeString, 2)) if err := utils.Chdir(".."); err != nil { t.Fatal(err) } utils.Execute(t, cmd, params, true, "Not found") }
func configSetTest(t *testing.T, params *utils.DeisTestConfig) { utils.Execute(t, configSetCmd, params, false, "讲台") utils.CheckList(t, appsInfoCmd, params, "(v5)", false) utils.Execute(t, configSet2Cmd, params, false, "10") utils.CheckList(t, appsInfoCmd, params, "(v6)", false) utils.Execute(t, configSetHealthcheckCmd, params, false, "/") utils.CheckList(t, appsInfoCmd, params, "(v7)", false) }
func authPasswdTest(t *testing.T, params *utils.DeisTestConfig) { password := "******" utils.AuthPasswd(t, params, password) cmd := authLoginCmd utils.Execute(t, cmd, params, true, "400 BAD REQUEST") params.Password = password utils.Execute(t, cmd, params, false, "") }
// buildsScaleTest ensures that we can use a Procfile-based workflow for `deis pull`. func buildsScaleTest(t *testing.T, params *utils.DeisTestConfig) { if err := utils.Chdir(params.ExampleApp); err != nil { t.Fatal(err) } utils.Execute(t, "scale worker=1 --app={{.AppName}}", params, false, "") utils.Execute(t, "logs --app={{.AppName}}", params, false, "hi") if err := utils.Chdir(".."); err != nil { t.Fatal(err) } }
func domainsTest(t *testing.T, cfg *utils.DeisTestConfig) { utils.Execute(t, domainsAddCmd, cfg, false, "done") // ensure both the root domain and the custom domain work utils.CurlApp(t, *cfg) utils.Curl(t, fmt.Sprintf("http://%s", cfg.AppDomain)) utils.Execute(t, domainsRemoveCmd, cfg, false, "done") // only the root domain should work now utils.CurlApp(t, *cfg) // TODO (bacongobbler): add test to ensure that the custom domain fails to connect }
func appsCreateTest(t *testing.T, params *utils.DeisTestConfig) { wd, _ := os.Getwd() defer os.Chdir(wd) if err := utils.Chdir(params.ExampleApp); err != nil { t.Fatal(err) } cmd := appsCreateCmd utils.Execute(t, cmd, params, false, "") utils.Execute(t, cmd, params, true, "App with this Id already exists") }
func appsRunTest(t *testing.T, params *utils.DeisTestConfig) { cmd := appsRunCmd if err := utils.Chdir(params.ExampleApp); err != nil { t.Fatal(err) } utils.Execute(t, cmd, params, false, "") if err := utils.Chdir(".."); err != nil { t.Fatal(err) } utils.Execute(t, cmd, params, true, "Not found") }
func limitsUnsetTest(t *testing.T, cfg *utils.DeisTestConfig, ver int) { cpuCmd, memCmd := limitsUnsetCPUCmd, limitsUnsetMemCmd if strings.Contains(cfg.ExampleApp, "dockerfile") { cpuCmd = strings.Replace(cpuCmd, "web", "cmd", 1) memCmd = strings.Replace(memCmd, "web", "cmd", 1) } utils.Execute(t, cpuCmd, cfg, false, "Unlimited") utils.Execute(t, limitsListCmd, cfg, false, "Unlimited") utils.Execute(t, memCmd, cfg, false, "Unlimited") utils.Execute(t, limitsListCmd, cfg, false, "Unlimited") }
func appsCreateTest(t *testing.T, params *utils.DeisTestConfig) { wd, _ := os.Getwd() defer os.Chdir(wd) if err := utils.Chdir(params.ExampleApp); err != nil { t.Fatal(err) } // TODO: move --buildpack to client unit tests utils.Execute(t, appsCreateCmdBuildpack, params, false, "BUILDPACK_URL") utils.Execute(t, appsDestroyCmdNoApp, params, false, "") utils.Execute(t, appsCreateCmd, params, false, "") utils.Execute(t, appsCreateCmd, params, true, "App with this Id already exists") }
func authPasswdTest(t *testing.T, params *utils.DeisTestConfig) { password := "******" params.NewPassword = password cmd := authPasswdCmd utils.Execute(t, cmd, params, false, "") params.Password = "******" utils.Execute(t, cmd, params, true, "Password change failed") cmd = authLoginCmd utils.Execute(t, cmd, params, true, "400 BAD REQUEST") params.Password = password utils.Execute(t, cmd, params, false, "") }
func authCancel(t *testing.T, params *utils.DeisTestConfig) { utils.Execute(t, authCancelCmd, params, false, "Account cancelled") user := utils.GetGlobalConfig() // Admins can delete other users. user.UserName, user.Password = "******", "test" utils.Execute(t, authRegisterCmd, user, false, "") admin := utils.GetGlobalConfig() utils.Execute(t, authLoginCmd, admin, false, "") utils.Execute(t, authCancelAdminCmd, user, false, "Account cancelled") // Make sure the admin is still logged in utils.CheckList(t, authWhoamiCmd, admin, admin.UserName, false) }
func authCancel(t *testing.T, params *utils.DeisTestConfig) { utils.Execute(t, authCancelCmd, params, false, "Account cancelled") user := utils.GetGlobalConfig() // Admins can delete other users. user.UserName, user.Password = "******", "test" utils.Execute(t, authRegisterCmd, user, false, "") admin := utils.GetGlobalConfig() utils.Execute(t, authLoginCmd, admin, false, "") utils.Execute(t, authCancelAdminCmd, user, false, "Account cancelled") // Make sure the user's config was not purged after auth:cancel --username utils.Execute(t, authWhoamiCmd, admin, false, "You are "+admin.UserName) }
func TestPs(t *testing.T) { params := psSetup(t) psScaleTest(t, params) appsOpenTest(t, params) psListTest(t, params, false) utils.AppsDestroyTest(t, params) utils.Execute(t, psScaleCmd, params, true, "404 NOT FOUND") // ensure we can choose our preferred beverage utils.Execute(t, psScaleCmd, params, true, "but first, coffee!") if err := os.Setenv("DEIS_DRINK_OF_CHOICE", "tea"); err != nil { t.Fatal(err) } utils.Execute(t, psScaleCmd, params, true, "but first, tea!") }
func certsTest(t *testing.T, cfg *utils.DeisTestConfig) { utils.Execute(t, domainsAddCmd, cfg, false, "done") utils.Execute(t, certsAddCmd, cfg, false, cfg.AppDomain) // wait for the certs to be populated in the router; cron takes up to 1 minute fmt.Println("sleeping for 60 seconds until certs are generated...") time.Sleep(60 * time.Second) fmt.Println("ok") // ensure the custom domain's SSL endpoint works utils.Curl(t, fmt.Sprintf("https://%s", cfg.AppDomain)) utils.Execute(t, certsRemoveCmd, cfg, false, "done") // only the root domain should work now utils.CurlApp(t, *cfg) // TODO (bacongobbler): add test to ensure that the custom domain fails to connect }
func appsLogsTest(t *testing.T, params *utils.DeisTestConfig) { cmd := appsLogsCmd // test for application lifecycle logs utils.Execute(t, cmd, params, false, "204 NO CONTENT") if err := utils.Chdir(params.ExampleApp); err != nil { t.Fatal(err) } utils.Execute(t, gitPushCmd, params, false, "") utils.Curl(t, params) utils.Execute(t, cmd, params, false, "") if err := utils.Chdir(".."); err != nil { t.Fatal(err) } }
func limitsSetTest(t *testing.T, cfg *utils.DeisTestConfig, ver int) { cpuCmd, memCmd := limitsSetCPUCmd, limitsSetMemCmd // regression test for https://github.com/deis/deis/issues/1563 // previously the client would throw a stack trace with empty limits utils.Execute(t, limitsListCmd, cfg, false, "Unlimited") if strings.Contains(cfg.ExampleApp, "dockerfile") { cpuCmd = strings.Replace(cpuCmd, "web", "cmd", 1) memCmd = strings.Replace(memCmd, "web", "cmd", 1) } utils.Execute(t, cpuCmd, cfg, false, "512") utils.Execute(t, limitsListCmd, cfg, false, "512") utils.Execute(t, memCmd, cfg, false, "256M") utils.Execute(t, limitsListCmd, cfg, false, "256M") }
func psSetup(t *testing.T) *utils.DeisTestConfig { cfg := utils.GetGlobalConfig() cfg.AppName = "pssample" utils.Execute(t, authLoginCmd, cfg, false, "") utils.Execute(t, gitCloneCmd, cfg, false, "") if err := utils.Chdir(cfg.ExampleApp); err != nil { t.Fatal(err) } utils.Execute(t, appsCreateCmd, cfg, false, "") utils.Execute(t, gitPushCmd, cfg, false, "") if err := utils.Chdir(".."); err != nil { t.Fatal(err) } return cfg }
func appsLogsTest(t *testing.T, params *utils.DeisTestConfig) { cmd := appsLogsCmd utils.Execute(t, cmd, params, true, "204 NO CONTENT") if err := utils.Chdir(params.ExampleApp); err != nil { t.Fatal(err) } utils.Execute(t, gitPushCmd, params, false, "") // TODO: nginx needs a few seconds to wake up here--fixme! time.Sleep(5000 * time.Millisecond) utils.Curl(t, params) utils.Execute(t, cmd, params, false, "") if err := utils.Chdir(".."); err != nil { t.Fatal(err) } }
func appsRunTest(t *testing.T, params *utils.DeisTestConfig) { cmd := appsRunCmd if err := utils.Chdir(params.ExampleApp); err != nil { t.Fatal(err) } utils.CheckList(t, cmd, params, "Hello, 世界", false) utils.Execute(t, "apps:run env", params, true, "GIT_SHA") // run a REALLY large command to test https://github.com/deis/deis/issues/2046 largeString := randomString(1024) utils.Execute(t, "apps:run echo "+largeString, params, false, largeString) if err := utils.Chdir(".."); err != nil { t.Fatal(err) } utils.Execute(t, cmd, params, true, "Not found") }
func cookieTest(t *testing.T, params *utils.DeisTestConfig) { // Regression test for https://github.com/deis/deis/pull/1136 // Ensure that cookies are cleared on auth:register and auth:cancel user, err := user.Current() if err != nil { t.Fatal(err) } cookieJar := user.HomeDir + "/.deis/cookies.txt" utils.Execute(t, authRegisterCmd, params, false, "") cmd := "cat " + cookieJar utils.CheckList(t, cmd, params, "csrftoken", false) utils.CheckList(t, cmd, params, "sessionid", false) info, err := os.Stat(cookieJar) if err != nil { t.Fatal(err) } mode := info.Mode().String() expected := "-rw-------" if mode != expected { t.Fatalf("%s has wrong mode:\n current: %s\n expected: %s", cookieJar, mode, expected) } utils.AuthCancel(t, params) utils.CheckList(t, cmd, params, "csrftoken", true) utils.CheckList(t, cmd, params, "sessionid", true) }
func TestHealthcheck(t *testing.T) { client := utils.HTTPClient() cfg := healthcheckSetup(t) done := make(chan bool, 1) url := fmt.Sprintf("http://%s.%s", cfg.AppName, cfg.Domain) utils.Execute(t, healthcheckGoodCmd, cfg, false, "/") go func() { // there should never be any downtime during these health check operations psScaleTest(t, cfg, psScaleCmd) cfg.ProcessNum = "1" psScaleTest(t, cfg, psScaleCmd) // kill healthcheck goroutine done <- true }() // run health checks in parallel while performing operations fmt.Printf("starting health checks at %s\n", url) loop: for { select { case <-done: fmt.Println("done performing health checks") break loop default: doHealthCheck(t, client, url) } } utils.AppsDestroyTest(t, cfg) }
// buildsCreateTest uses the `deis builds:create` (or `deis pull`) command // to promote a build from an existing docker image. func buildsCreateTest(t *testing.T, params *utils.DeisTestConfig) { params.AppName = "deispullsample" params.ImageID = "deis/example-go:latest" params.ExampleApp = "example-deis-pull" if err := os.Mkdir(params.ExampleApp, 0755); err != nil { t.Fatal(err) } if err := utils.Chdir(params.ExampleApp); err != nil { t.Fatal(err) } utils.Execute(t, appsCreateCmdNoRemote, params, false, "") utils.Execute(t, buildsCreateCmd, params, false, "") if err := utils.Chdir(".."); err != nil { t.Fatal(err) } }
func TestUsers(t *testing.T) { params := utils.GetGlobalConfig() user := utils.GetGlobalConfig() user.UserName, user.Password = "******", "test" user.AppName = params.AppName utils.Execute(t, authRegisterCmd, user, false, "") usersListTest(t, params, user) }
func TestPs(t *testing.T) { params := psSetup(t) psScaleTest(t, params) appsOpenTest(t, params) psListTest(t, params, false) utils.AppsDestroyTest(t, params) utils.Execute(t, psScaleCmd, params, true, "404 NOT FOUND") }
func appsLogsTest(t *testing.T, params *utils.DeisTestConfig) { cmd := appsLogsCmd // test for application lifecycle logs utils.Execute(t, cmd, params, false, "204 NO CONTENT") if err := utils.Chdir(params.ExampleApp); err != nil { t.Fatal(err) } utils.Execute(t, gitPushCmd, params, false, "") utils.CurlApp(t, *params) utils.Execute(t, cmd, params, false, "created initial release") utils.Execute(t, cmd, params, false, "listening on 5000...") utils.Execute(t, appsLogsLimitCmd, params, false, "") if err := utils.Chdir(".."); err != nil { t.Fatal(err) } }