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

     1  package tests
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/deiscc/workflow-e2e/tests/cmd"
     7  	"github.com/deiscc/workflow-e2e/tests/cmd/apps"
     8  	"github.com/deiscc/workflow-e2e/tests/cmd/auth"
     9  	"github.com/deiscc/workflow-e2e/tests/model"
    10  	"github.com/deiscc/workflow-e2e/tests/settings"
    11  
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/ginkgo/extensions/table"
    14  	. "github.com/onsi/gomega"
    15  	. "github.com/onsi/gomega/gbytes"
    16  	. "github.com/onsi/gomega/gexec"
    17  )
    18  
    19  var _ = Describe("deis registry", func() {
    20  
    21  	Context("with an existing user", func() {
    22  
    23  		var user model.User
    24  
    25  		BeforeEach(func() {
    26  			user = auth.RegisterAndLogin()
    27  		})
    28  
    29  		AfterEach(func() {
    30  			auth.Cancel(user)
    31  		})
    32  
    33  		Context("who owns an existing app", func() {
    34  
    35  			var app model.App
    36  
    37  			BeforeEach(func() {
    38  				app = apps.Create(user, "--no-remote")
    39  			})
    40  
    41  			AfterEach(func() {
    42  				apps.Destroy(user, app)
    43  			})
    44  
    45  			Specify("that user can list that app's registry information", func() {
    46  				sess, err := cmd.Start("deis registry:list --app=%s", &user, app.Name)
    47  				Eventually(sess).Should(Say("=== %s Registry", app.Name))
    48  				Expect(err).NotTo(HaveOccurred())
    49  				Eventually(sess).Should(Exit(0))
    50  			})
    51  
    52  			Specify("that user cannot unset an invalid registry information", func() {
    53  				sess, err := cmd.Start("deis registry:unset --app=%s munkafolyamat", &user, app.Name)
    54  				Eventually(sess).ShouldNot(Say(`munkafolyamat\s+yeah`, app.Name))
    55  				Expect(err).NotTo(HaveOccurred())
    56  				Eventually(sess).Should(Exit(1))
    57  			})
    58  
    59  			Specify("that user can set a valid registry information", func() {
    60  				// Setting a port first is required for a private registry
    61  				sess, err := cmd.Start("deis config:set -a %s PORT=5000", &user, app.Name)
    62  				Expect(err).NotTo(HaveOccurred())
    63  				Eventually(sess).Should(Say("Creating config"))
    64  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Config", app.Name))
    65  				Eventually(sess).Should(Say(`PORT\s+5000`))
    66  				Expect(err).NotTo(HaveOccurred())
    67  				Eventually(sess).Should(Exit(0))
    68  
    69  				sess, err = cmd.Start("deis registry:set --app=%s username=bob", &user, app.Name)
    70  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Registry", app.Name))
    71  				Eventually(sess).Should(Say(`username\s+bob`))
    72  				Expect(err).NotTo(HaveOccurred())
    73  				Eventually(sess).Should(Exit(0))
    74  
    75  				sess, err = cmd.Start("deis registry:list --app=%s", &user, app.Name)
    76  				Eventually(sess).Should(Say("=== %s Registry", app.Name))
    77  				Eventually(sess).Should(Say(`username\s+bob`))
    78  				Expect(err).NotTo(HaveOccurred())
    79  				Eventually(sess).Should(Exit(0))
    80  			})
    81  
    82  			Specify("that user can not deploy from a private registry due to lack of credentials", func() {
    83  				// do an unsuccessful deploy
    84  				image := "quay.io/deiscc/e2e-private-registry-test"
    85  				sess, err := cmd.Start("deis pull --app=%s %s", &user, app.Name, image)
    86  				Expect(err).NotTo(HaveOccurred())
    87  				Eventually(sess).Should(Say("Creating build..."))
    88  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Exit(1))
    89  				time.Sleep(10 * time.Second)
    90  			})
    91  
    92  			Specify("that user can deploy from a private registry using registry credentials", func() {
    93  				// Setting a port first is required for a private registry
    94  				sess, err := cmd.Start("deis config:set -a %s PORT=8080", &user, app.Name)
    95  				Expect(err).NotTo(HaveOccurred())
    96  				Eventually(sess).Should(Say("Creating config"))
    97  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Config", app.Name))
    98  				Eventually(sess).Should(Say(`PORT\s+8080`))
    99  				Expect(err).NotTo(HaveOccurred())
   100  				Eventually(sess).Should(Exit(0))
   101  
   102  				// read-only access
   103  				registry_creds := "TP5BS3NHW0OZ20GER4IORTIJF90J48KKJ8NX8YC7Z22N5P7WE27BRKVMQ4QAEID8"
   104  				sess, err = cmd.Start("deis registry:set --app=%s username=deiscc+e2e_registry password=%s", &user, app.Name, registry_creds)
   105  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Registry", app.Name))
   106  				Expect(err).NotTo(HaveOccurred())
   107  				Eventually(sess).Should(Exit(0))
   108  
   109  				// do a successful deploy
   110  				image := "quay.io/deiscc/e2e-private-registry-test"
   111  				sess, err = cmd.Start("deis pull --app=%s %s", &user, app.Name, image)
   112  				Expect(err).NotTo(HaveOccurred())
   113  				Eventually(sess).Should(Say("Creating build..."))
   114  				Eventually(sess, settings.MaxEventuallyTimeout).Should(Exit(0))
   115  				time.Sleep(10 * time.Second)
   116  			})
   117  
   118  			Context("and registry information has already been added to the app", func() {
   119  
   120  				BeforeEach(func() {
   121  					// Setting a port first is required
   122  					sess, err := cmd.Start("deis config:set -a %s PORT=5000", &user, app.Name)
   123  					Expect(err).NotTo(HaveOccurred())
   124  					Eventually(sess).Should(Say("Creating config"))
   125  					Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Config", app.Name))
   126  					Eventually(sess).Should(Say(`PORT\s+5000`))
   127  					Expect(err).NotTo(HaveOccurred())
   128  					Eventually(sess).Should(Exit(0))
   129  
   130  					sess, err = cmd.Start("deis registry:set --app=%s username=bob", &user, app.Name)
   131  					Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Registry", app.Name))
   132  					Eventually(sess).Should(Say(`username\s+bob`))
   133  					Expect(err).NotTo(HaveOccurred())
   134  					Eventually(sess).Should(Exit(0))
   135  				})
   136  
   137  				Specify("that user can unset that registry information from that app", func() {
   138  					sess, err := cmd.Start("deis registry:unset --app=%s username", &user, app.Name)
   139  					Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("=== %s Registry", app.Name))
   140  					Eventually(sess).ShouldNot(Say(`username\s+bob`))
   141  					Expect(err).NotTo(HaveOccurred())
   142  					Eventually(sess).Should(Exit(0))
   143  
   144  					sess, err = cmd.Start("deis registry:list --app=%s", &user, app.Name)
   145  					Eventually(sess).Should(Say("=== %s Registry", app.Name))
   146  					Eventually(sess).ShouldNot(Say(`username\s+bob`))
   147  					Eventually(sess).ShouldNot(Say(`munkafolyamat\s+yeah`, app.Name))
   148  					Expect(err).NotTo(HaveOccurred())
   149  					Eventually(sess).Should(Exit(0))
   150  				})
   151  
   152  			})
   153  
   154  		})
   155  
   156  	})
   157  
   158  	DescribeTable("any user can get command-line help for registry", func(command string, expected string) {
   159  		sess, err := cmd.Start(command, nil)
   160  		Eventually(sess).Should(Say(expected))
   161  		Expect(err).NotTo(HaveOccurred())
   162  		Eventually(sess).Should(Exit(0))
   163  		// TODO: test that help output was more than five lines long
   164  	},
   165  		Entry("helps on \"help registry\"",
   166  			"deis help registry", "Valid commands for registry:"),
   167  		Entry("helps on \"registry -h\"",
   168  			"deis registry -h", "Valid commands for registry:"),
   169  		Entry("helps on \"registry --help\"",
   170  			"deis registry --help", "Valid commands for registry:"),
   171  		Entry("helps on \"help registry:list\"",
   172  			"deis help registry:list", "Lists registry information for an application."),
   173  		Entry("helps on \"registry:list -h\"",
   174  			"deis registry:list -h", "Lists registry information for an application."),
   175  		Entry("helps on \"registry:list --help\"",
   176  			"deis registry:list --help", "Lists registry information for an application."),
   177  		Entry("helps on \"help registry:set\"",
   178  			"deis help registry:set", "Sets registry information for an application."),
   179  		Entry("helps on \"registry:set -h\"",
   180  			"deis registry:set -h", "Sets registry information for an application."),
   181  		Entry("helps on \"registry:set --help\"",
   182  			"deis registry:set --help", "Sets registry information for an application."),
   183  		Entry("helps on \"help registry:unset\"",
   184  			"deis help registry:unset", "Unsets registry information for an application."),
   185  		Entry("helps on \"registry:unset -h\"",
   186  			"deis registry:unset -h", "Unsets registry information for an application."),
   187  		Entry("helps on \"registry:unset --help\"",
   188  			"deis registry:unset --help", "Unsets registry information for an application."),
   189  	)
   190  
   191  })