github.com/deis/workflow-e2e@v2.12.2-0.20180227201524-4105be7001fe+incompatible/tests/apps_test.go (about)

     1  package tests
     2  
     3  import (
     4  	"os"
     5  	"strings"
     6  
     7  	deis "github.com/deis/controller-sdk-go"
     8  	"github.com/deis/workflow-e2e/tests/cmd"
     9  	"github.com/deis/workflow-e2e/tests/cmd/apps"
    10  	"github.com/deis/workflow-e2e/tests/cmd/auth"
    11  	"github.com/deis/workflow-e2e/tests/cmd/builds"
    12  	"github.com/deis/workflow-e2e/tests/model"
    13  	"github.com/deis/workflow-e2e/tests/settings"
    14  	"github.com/deis/workflow-e2e/tests/util"
    15  
    16  	. "github.com/onsi/ginkgo"
    17  	. "github.com/onsi/gomega"
    18  	. "github.com/onsi/gomega/gbytes"
    19  	. "github.com/onsi/gomega/gexec"
    20  )
    21  
    22  var _ = Describe("deis apps", func() {
    23  
    24  	Context("with an existing user", func() {
    25  
    26  		var user model.User
    27  
    28  		BeforeEach(func() {
    29  			user = auth.RegisterAndLogin()
    30  		})
    31  
    32  		AfterEach(func() {
    33  			auth.Cancel(user)
    34  		})
    35  
    36  		Specify("that user can create an app without a git remote", func() {
    37  			app := apps.Create(user, "--no-remote")
    38  			apps.Destroy(user, app)
    39  		})
    40  
    41  		Specify("that user can create an app that uses a custom buildpack", func() {
    42  			app := apps.Create(user, "--no-remote", "--buildpack https://weird-buildpacks.io/lisp")
    43  			defer apps.Destroy(user, app)
    44  			sess, err := cmd.Start("deis config:list -a %s", &user, app.Name)
    45  			Eventually(sess).Should(Say("BUILDPACK_URL"))
    46  			Expect(err).NotTo(HaveOccurred())
    47  			Eventually(sess).Should(Exit(0))
    48  		})
    49  
    50  		Context("and an app that does not exist", func() {
    51  
    52  			bogusAppName := "bogus-app-name"
    53  
    54  			Specify("that user cannot get information about that app", func() {
    55  				sess, err := cmd.Start("deis info -a %s", &user, bogusAppName)
    56  				Eventually(sess.Err).Should(Say(util.PrependError(apps.ErrNoAppMatch)))
    57  				Expect(err).NotTo(HaveOccurred())
    58  				Eventually(sess).Should(Exit(1))
    59  			})
    60  
    61  			Specify("that user cannot retrieve logs for that app", func() {
    62  				sess, err := cmd.Start("deis logs -a %s", &user, bogusAppName)
    63  				Eventually(sess.Err).Should(Say(`Error: There are currently no log messages. Please check the following things:`))
    64  				Expect(err).NotTo(HaveOccurred())
    65  				Eventually(sess).Should(Exit(1))
    66  			})
    67  
    68  			Specify("that user cannot open that app", func() {
    69  				sess, err := cmd.Start("deis open -a %s", &user, bogusAppName)
    70  				Eventually(sess.Err).Should(Say(util.PrependError(apps.ErrNoAppMatch)))
    71  				Expect(err).NotTo(HaveOccurred())
    72  				Eventually(sess).Should(Exit(1))
    73  			})
    74  
    75  			Specify("that user cannot run a command in that app's environment", func() {
    76  				sess, err := cmd.Start("deis apps:run -a %s echo Hello, 世界", &user, bogusAppName)
    77  				Eventually(sess).Should(Say("Running 'echo Hello, 世界'..."))
    78  				Eventually(sess.Err).Should(Say(util.PrependError(apps.ErrNoAppMatch)))
    79  				Expect(err).NotTo(HaveOccurred())
    80  				Eventually(sess).ShouldNot(Exit(0))
    81  			})
    82  
    83  		})
    84  
    85  		Context("who owns an existing app", func() {
    86  
    87  			var app model.App
    88  
    89  			BeforeEach(func() {
    90  				app = apps.Create(user, "--no-remote")
    91  			})
    92  
    93  			AfterEach(func() {
    94  				apps.Destroy(user, app)
    95  			})
    96  
    97  			Specify("that user cannot create a new app with the same name", func() {
    98  				sess, err := cmd.Start("deis apps:create %s", &user, app.Name)
    99  				Eventually(sess.Err).Should(Say("Application with this id already exists."))
   100  				Expect(err).NotTo(HaveOccurred())
   101  				Eventually(sess).ShouldNot(Exit(0))
   102  			})
   103  
   104  			Context("and another user also exists", func() {
   105  
   106  				var otherUser model.User
   107  
   108  				BeforeEach(func() {
   109  					otherUser = auth.RegisterAndLogin()
   110  				})
   111  
   112  				AfterEach(func() {
   113  					auth.Cancel(otherUser)
   114  				})
   115  
   116  				Specify("that first user can transfer ownership to the other user", func() {
   117  					sess, err := cmd.Start("deis apps:transfer --app=%s %s", &user, app.Name, otherUser.Username)
   118  					Expect(err).NotTo(HaveOccurred())
   119  					Eventually(sess).Should(Exit(0))
   120  					sess, err = cmd.Start("deis info -a %s", &user, app.Name)
   121  					Eventually(sess.Err).Should(Say(util.PrependError(deis.ErrForbidden)))
   122  					Expect(err).NotTo(HaveOccurred())
   123  					Eventually(sess).Should(Exit(1))
   124  					// Transer back or else cleanup will fail.
   125  					sess, err = cmd.Start("deis apps:transfer --app=%s %s", &otherUser, app.Name, user.Username)
   126  					Expect(err).NotTo(HaveOccurred())
   127  					Eventually(sess).Should(Exit(0))
   128  				})
   129  
   130  			})
   131  
   132  		})
   133  
   134  		Context("who has a local git repo containing source code", func() {
   135  
   136  			BeforeEach(func() {
   137  				output, err := cmd.Execute(`git clone https://github.com/deis/example-go.git`)
   138  				Expect(err).NotTo(HaveOccurred(), output)
   139  			})
   140  
   141  			Specify("that user can create an app with a git remote", func() {
   142  				os.Chdir("example-go")
   143  				app := apps.Create(user)
   144  				apps.Destroy(user, app)
   145  			})
   146  
   147  		})
   148  
   149  		Context("who owns an existing app that has already been deployed", func() {
   150  
   151  			uuidRegExp := `[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}`
   152  			procsRegexp := `(%s-[\w-]+) up \(v\d+\)`
   153  			var app model.App
   154  
   155  			BeforeEach(func() {
   156  				app = apps.Create(user, "--no-remote")
   157  				builds.Create(user, app)
   158  			})
   159  
   160  			AfterEach(func() {
   161  				apps.Destroy(user, app)
   162  			})
   163  
   164  			Specify("that user can get information about that app", func() {
   165  				sess, err := cmd.Start("deis info -a %s", &user, app.Name)
   166  				Eventually(sess).Should(Say("=== %s Application", app.Name))
   167  				Eventually(sess).Should(Say(`uuid:\s*%s`, uuidRegExp))
   168  				Eventually(sess).Should(Say(`url:\s*%s`, strings.Replace(app.URL, "http://", "", 1)))
   169  				Eventually(sess).Should(Say(`owner:\s*%s`, user.Username))
   170  				Eventually(sess).Should(Say(`id:\s*%s`, app.Name))
   171  				Eventually(sess).Should(Say("=== %s Processes", app.Name))
   172  				Eventually(sess).Should(Say(procsRegexp, app.Name))
   173  				Eventually(sess).Should(Say("=== %s Domains", app.Name))
   174  				Eventually(sess).Should(Say("%s", app.Name))
   175  				Expect(err).NotTo(HaveOccurred())
   176  				Eventually(sess).Should(Exit(0))
   177  			})
   178  
   179  			Specify("that user can retrieve logs for that app", func() {
   180  				sess, err := cmd.Start("deis logs -a %s", &user, app.Name)
   181  				Eventually(sess).Should(SatisfyAll(
   182  					Say(`(.+) (deis\[controller\]: INFO config test\-.* updated)`),
   183  					Say(`(.*) (deis\[controller\]: INFO test\-.* created initial release)`),
   184  					Say(`(.*) (deis\[controller\]: INFO appsettings test\-.* updated)`),
   185  					Say(`(.*) (deis\[controller\]: INFO domain test\-.* added)`),
   186  					Say(`(.*) (deis\[controller\]: INFO build test\-.* created)`)))
   187  				Expect(err).NotTo(HaveOccurred())
   188  				Eventually(sess).Should(Exit(0))
   189  			})
   190  
   191  			Specify("that user can open that app", func() {
   192  				apps.Open(user, app)
   193  			})
   194  
   195  			Specify("that user can run a command in that app's environment", func() {
   196  				sess, err := cmd.Start("deis apps:run --app=%s echo Hello, 世界", &user, app.Name)
   197  				Expect(err).NotTo(HaveOccurred())
   198  				Eventually(sess, (settings.MaxEventuallyTimeout)).Should(Say("Hello, 世界"))
   199  				Eventually(sess).Should(Exit(0))
   200  			})
   201  
   202  			Specify("that user can run a command with dashes in that app's environment", func() {
   203  				sess, err := cmd.Start("deis apps:run --app=%s -- ls -alh", &user, app.Name)
   204  				Expect(err).NotTo(HaveOccurred())
   205  				// Can't assume too much about arbitrary "ls" output
   206  				Eventually(sess, (settings.MaxEventuallyTimeout)).Should(Say("total "))
   207  				Eventually(sess, (settings.MaxEventuallyTimeout)).Should(Say(" .."))
   208  				Eventually(sess).Should(Exit(0))
   209  			})
   210  
   211  			Specify("that user can run a command with quotes in that app's environment", func() {
   212  				sess, err := cmd.Start("deis apps:run --app=%s echo 'Hello, \\\"高座\\\"'", &user, app.Name)
   213  				Expect(err).NotTo(HaveOccurred())
   214  				Eventually(sess, (settings.MaxEventuallyTimeout)).Should(Say("Hello, \"高座\""))
   215  				Eventually(sess).Should(Exit(0))
   216  			})
   217  
   218  			// TODO: Test is broken on CI in GKE
   219  			XSpecify("that user can run a command with lengthy output in that app's environment", func() {
   220  				sess, err := cmd.Start("deis apps:run --app=%s dd if=/dev/urandom bs=3072 count=1000", &user, app.Name)
   221  				Expect(err).NotTo(HaveOccurred())
   222  				Eventually(sess, (settings.MaxEventuallyTimeout)).Should(Exit(0))
   223  				Expect(len(sess.Out.Contents())).To(BeNumerically(">=", 3072000))
   224  			})
   225  
   226  			Specify("that user can't run a bogus command in that app's environment", func() {
   227  				sess, err := cmd.Start("deis apps:run --app=%s /usr/bin/boguscmd", &user, app.Name)
   228  				Expect(err).NotTo(HaveOccurred())
   229  				Eventually(sess.Err, (settings.MaxEventuallyTimeout)).Should(Say("No such file or directory"))
   230  				Eventually(sess).ShouldNot(Exit(0))
   231  			})
   232  
   233  		})
   234  
   235  	})
   236  
   237  })