github.com/deiscc/workflow-e2e@v0.0.0-20181208071258-117299af888f/tests/maintenance_test.go (about)

     1  package tests
     2  
     3  import (
     4  	"fmt"
     5  	"strconv"
     6  
     7  	"github.com/deiscc/workflow-e2e/tests/cmd"
     8  	"github.com/deiscc/workflow-e2e/tests/cmd/apps"
     9  	"github.com/deiscc/workflow-e2e/tests/cmd/auth"
    10  	"github.com/deiscc/workflow-e2e/tests/cmd/builds"
    11  	"github.com/deiscc/workflow-e2e/tests/model"
    12  	"github.com/deiscc/workflow-e2e/tests/settings"
    13  
    14  	. "github.com/onsi/ginkgo"
    15  	. "github.com/onsi/gomega"
    16  	. "github.com/onsi/gomega/gbytes"
    17  	. "github.com/onsi/gomega/gexec"
    18  )
    19  
    20  var _ = Describe("deis maintenance", func() {
    21  
    22  	Context("with an existing user", func() {
    23  
    24  		var user model.User
    25  
    26  		BeforeEach(func() {
    27  			user = auth.RegisterAndLogin()
    28  		})
    29  
    30  		AfterEach(func() {
    31  			auth.Cancel(user)
    32  		})
    33  
    34  		Context("who owns an existing app that has already been deployed", func() {
    35  
    36  			var app model.App
    37  
    38  			BeforeEach(func() {
    39  				app = apps.Create(user, "--no-remote")
    40  				builds.Create(user, app)
    41  			})
    42  
    43  			AfterEach(func() {
    44  				apps.Destroy(user, app)
    45  			})
    46  
    47  			Specify("can list that app's maintenance info", func() {
    48  				sess, err := cmd.Start("deis maintenance:info --app=%s", &user, app.Name)
    49  				Eventually(sess).Should(Say("Maintenance mode is off.\n"))
    50  				Expect(err).NotTo(HaveOccurred())
    51  				Eventually(sess).Should(Exit(0))
    52  			})
    53  
    54  			Specify("can view app when maintenance mode is off", func() {
    55  				// curl the app's root URL and print just the HTTP response code
    56  				cmdRetryTimeout := 60
    57  				curlCmd := model.Cmd{CommandLineString: fmt.Sprintf(`curl -sL -w "%%{http_code}\\n" "%s" -o /dev/null`, app.URL)}
    58  				Eventually(cmd.Retry(curlCmd, strconv.Itoa(200), cmdRetryTimeout)).Should(BeTrue())
    59  			})
    60  
    61  			Specify("can enable/disable maintenance", func() {
    62  				sess, err := cmd.Start("deis maintenance:on --app=%s", &user, app.Name)
    63  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("done"))
    64  				Expect(err).NotTo(HaveOccurred())
    65  				Eventually(sess).Should(Exit(0))
    66  
    67  				sess, err = cmd.Start("deis maintenance:info --app=%s", &user, app.Name)
    68  				Eventually(sess).Should(Say("Maintenance mode is on.\n"))
    69  				Expect(err).NotTo(HaveOccurred())
    70  				Eventually(sess).Should(Exit(0))
    71  
    72  				// curl the app's root URL and print just the HTTP response code
    73  				cmdRetryTimeout := 60
    74  				curlCmd := model.Cmd{CommandLineString: fmt.Sprintf(`curl -sL -w "%%{http_code}\\n" "%s" -o /dev/null`, app.URL)}
    75  				Eventually(cmd.Retry(curlCmd, strconv.Itoa(503), cmdRetryTimeout)).Should(BeTrue())
    76  
    77  				sess, err = cmd.Start("deis maintenance:off --app=%s", &user, app.Name)
    78  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("done"))
    79  				Expect(err).NotTo(HaveOccurred())
    80  				Eventually(sess).Should(Exit(0))
    81  
    82  				sess, err = cmd.Start("deis maintenance:info --app=%s", &user, app.Name)
    83  				Eventually(sess).Should(Say("Maintenance mode is off.\n"))
    84  				Expect(err).NotTo(HaveOccurred())
    85  				Eventually(sess).Should(Exit(0))
    86  
    87  				cmdRetryTimeout = 60
    88  				curlCmd = model.Cmd{CommandLineString: fmt.Sprintf(`curl -sL -w "%%{http_code}\\n" "%s" -o /dev/null`, app.URL)}
    89  				Eventually(cmd.Retry(curlCmd, strconv.Itoa(200), cmdRetryTimeout)).Should(BeTrue())
    90  			})
    91  		})
    92  	})
    93  
    94  })