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

     1  package tests
     2  
     3  import (
     4  	"github.com/deis/workflow-e2e/tests/cmd"
     5  	"github.com/deis/workflow-e2e/tests/cmd/apps"
     6  	"github.com/deis/workflow-e2e/tests/cmd/auth"
     7  	"github.com/deis/workflow-e2e/tests/model"
     8  
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/ginkgo/extensions/table"
    11  	. "github.com/onsi/gomega"
    12  	. "github.com/onsi/gomega/gbytes"
    13  	. "github.com/onsi/gomega/gexec"
    14  )
    15  
    16  var _ = Describe("deis labels", func() {
    17  
    18  	Context("with an existing user", func() {
    19  
    20  		var user model.User
    21  
    22  		BeforeEach(func() {
    23  			user = auth.RegisterAndLogin()
    24  		})
    25  
    26  		AfterEach(func() {
    27  			auth.Cancel(user)
    28  		})
    29  
    30  		Context("who owns an existing app", func() {
    31  
    32  			var app model.App
    33  
    34  			BeforeEach(func() {
    35  				app = apps.Create(user, "--no-remote")
    36  			})
    37  
    38  			AfterEach(func() {
    39  				apps.Destroy(user, app)
    40  			})
    41  
    42  			Specify("that user can list that app's labels", func() {
    43  				sess, err := cmd.Start("deis labels:list --app=%s", &user, app.Name)
    44  				Eventually(sess).Should(Say("=== %s Label", app.Name))
    45  				Expect(err).NotTo(HaveOccurred())
    46  				Eventually(sess).Should(Exit(0))
    47  			})
    48  
    49  			Specify("that user cannot set an invalid label", func() {
    50  				sess, err := cmd.Start("deis labels:set --app=%s only_key", &user, app.Name)
    51  				Eventually(sess).ShouldNot(Say(`done`))
    52  				Eventually(sess.Err).Should(Say("only_key is invalid"))
    53  				Expect(err).NotTo(HaveOccurred())
    54  				Eventually(sess).Should(Exit(1))
    55  			})
    56  
    57  			Specify("that user cannot unset an non-exist label", func() {
    58  				sess, err := cmd.Start("deis labels:unset --app=%s not_exist", &user, app.Name)
    59  				Eventually(sess).ShouldNot(Say(`done`))
    60  				Eventually(sess.Err).Should(Say("not_exist does not exist"))
    61  				Expect(err).NotTo(HaveOccurred())
    62  				Eventually(sess).Should(Exit(1))
    63  			})
    64  
    65  			Specify("that user can set a valid tag", func() {
    66  				sess, err := cmd.Start("deis labels:set --app=%s team=bi service=frontend", &user, app.Name)
    67  				Eventually(sess).Should(Say(`Applying labels on %s...`, app.Name))
    68  				Eventually(sess).Should(Say("done"))
    69  				Expect(err).NotTo(HaveOccurred())
    70  				Eventually(sess).Should(Exit(0))
    71  
    72  				sess, err = cmd.Start("deis labels:list --app=%s", &user, app.Name)
    73  				Eventually(sess).Should(Say("=== %s Label", app.Name))
    74  				Eventually(sess).Should(Say(`service:\s+frontend`))
    75  				Eventually(sess).Should(Say(`team:\s+bi`))
    76  				Expect(err).NotTo(HaveOccurred())
    77  				Eventually(sess).Should(Exit(0))
    78  			})
    79  
    80  			Specify("that user can unset that label from that app", func() {
    81  				sess, err := cmd.Start("deis labels:set --app=%s zoo=animal", &user, app.Name)
    82  				Eventually(sess).Should(Say("done"))
    83  				Expect(err).NotTo(HaveOccurred())
    84  				Eventually(sess).Should(Exit(0))
    85  
    86  				sess, err = cmd.Start("deis labels:unset --app=%s zoo", &user, app.Name)
    87  				Eventually(sess).Should(Say(`Removing labels on %s...`, app.Name))
    88  				Eventually(sess).Should(Say("done"))
    89  				Expect(err).NotTo(HaveOccurred())
    90  				Eventually(sess).Should(Exit(0))
    91  
    92  				sess, err = cmd.Start("deis labels:list --app=%s", &user, app.Name)
    93  				Eventually(sess).Should(Say("=== %s Label", app.Name))
    94  				Eventually(sess).ShouldNot(Say("zoo", app.Name))
    95  				Expect(err).NotTo(HaveOccurred())
    96  				Eventually(sess).Should(Exit(0))
    97  			})
    98  
    99  			Context("and labels has already been added to the app", func() {
   100  
   101  				Specify("that user can add more labels to the apps", func() {
   102  					sess, err := cmd.Start("deis labels:set --app=%s team=frontend", &user, app.Name)
   103  					Eventually(sess).Should(Say("done"))
   104  					Expect(err).NotTo(HaveOccurred())
   105  					Eventually(sess).Should(Exit(0))
   106  
   107  					sess, err = cmd.Start("deis labels:set --app=%s zoo=animal", &user, app.Name)
   108  					Eventually(sess).Should(Say("done"))
   109  					Expect(err).NotTo(HaveOccurred())
   110  					Eventually(sess).Should(Exit(0))
   111  
   112  					sess, err = cmd.Start("deis labels:list --app=%s", &user, app.Name)
   113  					Eventually(sess).Should(Say("=== %s Label", app.Name))
   114  					Eventually(sess).Should(Say(`team:\s+frontend`))
   115  					Eventually(sess).Should(Say(`zoo:\s+animal`))
   116  					Expect(err).NotTo(HaveOccurred())
   117  					Eventually(sess).Should(Exit(0))
   118  				})
   119  
   120  			})
   121  
   122  		})
   123  
   124  	})
   125  
   126  	DescribeTable("any user can get command-line help for labels", func(command string, expected string) {
   127  		sess, err := cmd.Start(command, nil)
   128  		Eventually(sess).Should(Say(expected))
   129  		Expect(err).NotTo(HaveOccurred())
   130  		Eventually(sess).Should(Exit(0))
   131  	},
   132  		Entry("helps on \"help labels\"",
   133  			"deis help labels", "Valid commands for labels:"),
   134  		Entry("helps on \"labels -h\"",
   135  			"deis labels -h", "Valid commands for labels:"),
   136  		Entry("helps on \"labels --help\"",
   137  			"deis labels --help", "Valid commands for labels:"),
   138  		Entry("helps on \"help labels:list\"",
   139  			"deis help labels:list", "Prints a list of labels of the application."),
   140  		Entry("helps on \"labels:list -h\"",
   141  			"deis labels:list -h", "Prints a list of labels of the application."),
   142  		Entry("helps on \"labels:list --help\"",
   143  			"deis labels:list --help", "Prints a list of labels of the application."),
   144  		Entry("helps on \"help labels:set\"",
   145  			"deis help labels:set", "Sets labels for an application."),
   146  		Entry("helps on \"labels:set -h\"",
   147  			"deis labels:set -h", "Sets labels for an application."),
   148  		Entry("helps on \"labels:set --help\"",
   149  			"deis labels:set --help", "Sets labels for an application."),
   150  		Entry("helps on \"help labels:unset\"",
   151  			"deis help labels:unset", "Unsets labels for an application."),
   152  		Entry("helps on \"labels:unset -h\"",
   153  			"deis labels:unset -h", "Unsets labels for an application."),
   154  		Entry("helps on \"labels:unset --help\"",
   155  			"deis labels:unset --help", "Unsets labels for an application."),
   156  	)
   157  
   158  })