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

     1  package tests
     2  
     3  import (
     4  	"io/ioutil"
     5  
     6  	"github.com/deis/workflow-e2e/tests/cmd"
     7  	"github.com/deis/workflow-e2e/tests/cmd/apps"
     8  	"github.com/deis/workflow-e2e/tests/cmd/auth"
     9  	"github.com/deis/workflow-e2e/tests/cmd/builds"
    10  	"github.com/deis/workflow-e2e/tests/model"
    11  	"github.com/deis/workflow-e2e/tests/settings"
    12  
    13  	. "github.com/onsi/ginkgo"
    14  	. "github.com/onsi/ginkgo/extensions/table"
    15  	. "github.com/onsi/gomega"
    16  	. "github.com/onsi/gomega/gbytes"
    17  	. "github.com/onsi/gomega/gexec"
    18  )
    19  
    20  var _ = Describe("deis config", 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("that user can list environment variables on that app", func() {
    48  				sess, err := cmd.Start("deis config:list -a %s", &user, app.Name)
    49  				Eventually(sess).Should(Say("=== %s Config", app.Name))
    50  				Expect(err).NotTo(HaveOccurred())
    51  				Eventually(sess).Should(Exit(0))
    52  			})
    53  
    54  			Specify("that user can set environment variables on that app", func() {
    55  				sess, err := cmd.Start("deis config:set -a %s POWERED_BY=midi-chlorians", &user, app.Name)
    56  				Expect(err).NotTo(HaveOccurred())
    57  				Eventually(sess).Should(Say("Creating config"))
    58  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Config", app.Name))
    59  				Eventually(sess).Should(Say(`POWERED_BY\s+midi-chlorians`))
    60  				Expect(err).NotTo(HaveOccurred())
    61  				Eventually(sess).Should(Exit(0))
    62  
    63  				sess, err = cmd.Start("deis config:list -a %s", &user, app.Name)
    64  				Eventually(sess).Should(Say("=== %s Config", app.Name))
    65  				Eventually(sess).Should(Say(`POWERED_BY\s+midi-chlorians`))
    66  				Expect(err).NotTo(HaveOccurred())
    67  				Eventually(sess).Should(Exit(0))
    68  
    69  				sess, err = cmd.Start("deis run env -a %s", &user, app.Name)
    70  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("POWERED_BY=midi-chlorians"))
    71  				Expect(err).NotTo(HaveOccurred())
    72  				Eventually(sess).Should(Exit(0))
    73  			})
    74  
    75  			Specify("that user can set multiple environment variables at once on that app", func() {
    76  				sess, err := cmd.Start("deis config:set FOO=null BAR=nil -a %s", &user, app.Name)
    77  				Eventually(sess).Should(Say("Creating config"))
    78  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Config", app.Name))
    79  				output := string(sess.Out.Contents())
    80  				Expect(output).To(MatchRegexp(`FOO\s+null`))
    81  				Expect(output).To(MatchRegexp(`BAR\s+nil`))
    82  				Expect(err).NotTo(HaveOccurred())
    83  				Eventually(sess).Should(Exit(0))
    84  
    85  				sess, err = cmd.Start("deis config:list -a %s", &user, app.Name)
    86  				Eventually(sess).Should(Say("=== %s Config", app.Name))
    87  				output = string(sess.Out.Contents())
    88  				Expect(output).To(MatchRegexp(`FOO\s+null`))
    89  				Expect(output).To(MatchRegexp(`BAR\s+nil`))
    90  				Expect(err).NotTo(HaveOccurred())
    91  				Eventually(sess).Should(Exit(0))
    92  
    93  				sess, err = cmd.Start("deis run env -a %s", &user, app.Name)
    94  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("FOO=null"))
    95  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("BAR=nil"))
    96  				Expect(err).NotTo(HaveOccurred())
    97  				Eventually(sess).Should(Exit(0))
    98  			})
    99  
   100  			Specify("that user can set an environment variable containing spaces on that app", func() {
   101  				sess, err := cmd.Start(`deis config:set -a %s POWERED_BY=the\ Deis\ team`, &user, app.Name)
   102  				Eventually(sess).Should(Say("Creating config"))
   103  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Config", app.Name))
   104  				Eventually(sess).Should(Say(`POWERED_BY\s+the Deis team`))
   105  				Expect(err).NotTo(HaveOccurred())
   106  				Eventually(sess).Should(Exit(0))
   107  
   108  				sess, err = cmd.Start("deis config:list -a %s", &user, app.Name)
   109  				Eventually(sess).Should(Say("=== %s Config", app.Name))
   110  				Eventually(sess).Should(Say(`POWERED_BY\s+the Deis team`))
   111  				Expect(err).NotTo(HaveOccurred())
   112  				Eventually(sess).Should(Exit(0))
   113  
   114  				sess, err = cmd.Start("deis run -a %s env", &user, app.Name)
   115  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("POWERED_BY=the Deis team"))
   116  				Expect(err).NotTo(HaveOccurred())
   117  				Eventually(sess).Should(Exit(0))
   118  			})
   119  
   120  			It("that user can set a multi-line environment variable on that app", func() {
   121  				value := `This is
   122  a
   123  multiline string.`
   124  
   125  				sess, err := cmd.Start(`deis config:set -a %s FOO='%s'`, &user, app.Name, value)
   126  				Eventually(sess).Should(Say("Creating config"))
   127  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Config", app.Name))
   128  				Eventually(sess).Should(Say(`FOO\s+%s`, value))
   129  				Expect(err).NotTo(HaveOccurred())
   130  				Eventually(sess).Should(Exit(0))
   131  
   132  				sess, err = cmd.Start("deis config:list -a %s", &user, app.Name)
   133  				Eventually(sess).Should(Say("=== %s Config", app.Name))
   134  				Eventually(sess).Should(Say(`FOO\s+%s`, value))
   135  				Expect(err).NotTo(HaveOccurred())
   136  				Eventually(sess).Should(Exit(0))
   137  
   138  				sess, err = cmd.Start("deis run -a %s env", &user, app.Name)
   139  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("FOO=%s", value))
   140  				Expect(err).NotTo(HaveOccurred())
   141  				Eventually(sess).Should(Exit(0))
   142  			})
   143  
   144  			Specify("that user can set an environment variable with non-ASCII and multibyte chars on that app", func() {
   145  				sess, err := cmd.Start("deis config:set FOO=讲台 BAR=Þorbjörnsson BAZ=ноль -a %s", &user, app.Name)
   146  				Eventually(sess).Should(Say("Creating config"))
   147  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Config", app.Name))
   148  				output := string(sess.Out.Contents())
   149  				Expect(output).To(MatchRegexp(`FOO\s+讲台`))
   150  				Expect(output).To(MatchRegexp(`BAR\s+Þorbjörnsson`))
   151  				Expect(output).To(MatchRegexp(`BAZ\s+ноль`))
   152  				Expect(err).NotTo(HaveOccurred())
   153  				Eventually(sess).Should(Exit(0))
   154  
   155  				sess, err = cmd.Start("deis config:list -a %s", &user, app.Name)
   156  				Eventually(sess).Should(Say("=== %s Config", app.Name))
   157  				output = string(sess.Out.Contents())
   158  				Expect(output).To(MatchRegexp(`FOO\s+讲台`))
   159  				Expect(output).To(MatchRegexp(`BAR\s+Þorbjörnsson`))
   160  				Expect(output).To(MatchRegexp(`BAZ\s+ноль`))
   161  				Expect(err).NotTo(HaveOccurred())
   162  				Eventually(sess).Should(Exit(0))
   163  
   164  				sess, err = cmd.Start("deis run -a %s env", &user, app.Name)
   165  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Exit(0))
   166  				output = string(sess.Out.Contents())
   167  				Expect(output).To(ContainSubstring("FOO=讲台"))
   168  				Expect(output).To(ContainSubstring("BAR=Þorbjörnsson"))
   169  				Expect(output).To(ContainSubstring("BAZ=ноль"))
   170  				Expect(err).NotTo(HaveOccurred())
   171  				Eventually(sess).Should(Exit(0))
   172  			})
   173  
   174  			Context("and has already has an environment variable set", func() {
   175  
   176  				BeforeEach(func() {
   177  					sess, err := cmd.Start(`deis config:set -a %s FOO=xyzzy`, &user, app.Name)
   178  					Eventually(sess).Should(Say("Creating config"))
   179  					Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Config", app.Name))
   180  					Eventually(sess).Should(Say(`FOO\s+xyzzy`))
   181  					Expect(err).NotTo(HaveOccurred())
   182  					Eventually(sess).Should(Exit(0))
   183  				})
   184  
   185  				Specify("that user can unset that environment variable", func() {
   186  					sess, err := cmd.Start("deis config:unset -a %s FOO", &user, app.Name)
   187  					Eventually(sess).Should(Say("Removing config"))
   188  					Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Config", app.Name))
   189  					Eventually(sess).ShouldNot(Say(`FOO\s+xyzzy`))
   190  					Expect(err).NotTo(HaveOccurred())
   191  					Eventually(sess).Should(Exit(0))
   192  
   193  					sess, err = cmd.Start("deis config:list -a %s", &user, app.Name)
   194  					Eventually(sess).Should(Say("=== %s Config", app.Name))
   195  					Eventually(sess).ShouldNot(Say(`FOO\s+xyzzy`))
   196  					Expect(err).NotTo(HaveOccurred())
   197  					Eventually(sess).Should(Exit(0))
   198  
   199  					sess, err = cmd.Start("deis run -a %s env", &user, app.Name)
   200  					Eventually(sess, settings.MaxEventuallyTimeout).ShouldNot(Say("FOO=xyzzy"))
   201  					Expect(err).NotTo(HaveOccurred())
   202  					Eventually(sess).Should(Exit(0))
   203  				})
   204  
   205  				Specify("that user can pull the configuration to an .env file", func() {
   206  					sess, err := cmd.Start("deis config:pull -a %s", &user, app.Name)
   207  					// TODO: ginkgo seems to redirect deis' file output here, so just examine
   208  					// the output stream rather than reading in the .env file. Bug?
   209  					Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("FOO=xyzzy"))
   210  					Expect(err).NotTo(HaveOccurred())
   211  					Eventually(sess).Should(Exit(0))
   212  				})
   213  
   214  			})
   215  
   216  			Specify("that user can push configuration from an .env file", func() {
   217  				contents := []byte(`BIP=baz
   218  FOO=bar`)
   219  				err := ioutil.WriteFile(".env", contents, 0644)
   220  				Expect(err).NotTo(HaveOccurred())
   221  
   222  				sess, err := cmd.Start("deis config:push -a %s", &user, app.Name)
   223  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Exit(0))
   224  				Expect(err).NotTo(HaveOccurred())
   225  				Eventually(sess).Should(Exit(0))
   226  
   227  				// Config should appear in config:list.
   228  				sess, err = cmd.Start("deis config:list -a %s", &user, app.Name)
   229  				Expect(err).NotTo(HaveOccurred())
   230  				Eventually(sess).Should(Exit(0))
   231  
   232  				Eventually(sess).Should(Say("=== %s Config", app.Name))
   233  				Eventually(sess).Should(Say(`BIP\s+baz`))
   234  				Eventually(sess).Should(Say(`FOO\s+bar`))
   235  
   236  				// Config should be found within the app env vars (without any line endings).
   237  				sess, err = cmd.Start("deis run -a %s 'printf %%q $BIP'", &user, app.Name)
   238  				Expect(err).NotTo(HaveOccurred())
   239  				Eventually(sess).Should(Exit(0))
   240  				Eventually(sess).Should(Say("baz"))
   241  			})
   242  
   243  			Specify("that user can push configuration from an .env file with CRLF line endings", func() {
   244  				contents := []byte("BIP=baz\r\nFOO=bar\r\nWOO=goo\r\n")
   245  				err := ioutil.WriteFile(".env", contents, 0644)
   246  				Expect(err).NotTo(HaveOccurred())
   247  
   248  				sess, err := cmd.Start("deis config:push -a %s", &user, app.Name)
   249  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Exit(0))
   250  				Expect(err).NotTo(HaveOccurred())
   251  				Eventually(sess).Should(Exit(0))
   252  
   253  				// Config should appear in the config:list
   254  				Eventually(sess).Should(Say("=== %s Config", app.Name))
   255  				Eventually(sess).Should(Say(`BIP\s+baz`))
   256  				Eventually(sess).Should(Say(`FOO\s+bar`))
   257  				Eventually(sess).Should(Say(`WOO\s+goo`))
   258  				Eventually(sess).Should(Exit(0))
   259  
   260  				// Config should be found within the app env vars (without any line endings).
   261  				sess, err = cmd.Start("deis run -a %s 'printf %%q $WOO'", &user, app.Name)
   262  				Expect(err).NotTo(HaveOccurred())
   263  				Eventually(sess).Should(Exit(0))
   264  				Eventually(sess).Should(Say("goo"))
   265  			})
   266  
   267  		})
   268  
   269  	})
   270  
   271  	DescribeTable("any user can get command-line help for config", func(command string, expected string) {
   272  		sess, err := cmd.Start(command, nil)
   273  		Eventually(sess).Should(Say(expected))
   274  		Expect(err).NotTo(HaveOccurred())
   275  		Eventually(sess).Should(Exit(0))
   276  		// TODO: test that help output was more than five lines long
   277  	},
   278  		Entry("helps on \"help config\"",
   279  			"deis help config", "Valid commands for config:"),
   280  		Entry("helps on \"config -h\"",
   281  			"deis config -h", "Valid commands for config:"),
   282  		Entry("helps on \"config --help\"",
   283  			"deis config --help", "Valid commands for config:"),
   284  		Entry("helps on \"help config:list\"",
   285  			"deis help config:list", "Lists environment variables for an application."),
   286  		Entry("helps on \"config:list -h\"",
   287  			"deis config:list -h", "Lists environment variables for an application."),
   288  		Entry("helps on \"config:list --help\"",
   289  			"deis config:list --help", "Lists environment variables for an application."),
   290  		Entry("helps on \"help config:set\"",
   291  			"deis help config:set", "Sets environment variables for an application."),
   292  		Entry("helps on \"config:set -h\"",
   293  			"deis config:set -h", "Sets environment variables for an application."),
   294  		Entry("helps on \"config:set --help\"",
   295  			"deis config:set --help", "Sets environment variables for an application."),
   296  		Entry("helps on \"help config:unset\"",
   297  			"deis help config:unset", "Unsets an environment variable for an application."),
   298  		Entry("helps on \"config:unset -h\"",
   299  			"deis config:unset -h", "Unsets an environment variable for an application."),
   300  		Entry("helps on \"config:unset --help\"",
   301  			"deis config:unset --help", "Unsets an environment variable for an application."),
   302  		Entry("helps on \"help config:pull\"",
   303  			"deis help config:pull", "Extract all environment variables from an application for local use."),
   304  		Entry("helps on \"config:pull -h\"",
   305  			"deis config:pull -h", "Extract all environment variables from an application for local use."),
   306  		Entry("helps on \"config:pull --help\"",
   307  			"deis config:pull --help", "Extract all environment variables from an application for local use."),
   308  		Entry("helps on \"help config:push\"",
   309  			"deis help config:push", "Sets environment variables for an application."),
   310  		Entry("helps on \"config:push -h\"",
   311  			"deis config:push -h", "Sets environment variables for an application."),
   312  		Entry("helps on \"config:push --help\"",
   313  			"deis config:push --help", "Sets environment variables for an application."),
   314  	)
   315  
   316  })