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

     1  package certs
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	"github.com/deis/workflow-e2e/tests/cmd"
     8  	"github.com/deis/workflow-e2e/tests/model"
     9  	"github.com/deis/workflow-e2e/tests/settings"
    10  
    11  	. "github.com/onsi/gomega"
    12  	. "github.com/onsi/gomega/gbytes"
    13  	. "github.com/onsi/gomega/gexec"
    14  )
    15  
    16  var ErrNoCertMatch = errors.New("\"No Certificate matches the given query.\"")
    17  
    18  // The functions in this file implement SUCCESS CASES for commonly used `deis certs` subcommands.
    19  // This allows each of these to be re-used easily in multiple contexts.
    20  
    21  // List executes `deis certs:list` as the specified user.
    22  func List(user model.User) *Session {
    23  	sess, err := cmd.Start("deis certs:list", &user)
    24  	Expect(err).NotTo(HaveOccurred())
    25  	Eventually(sess).Should(Exit(0))
    26  	return sess
    27  }
    28  
    29  // Add executes `deis certs:add` as the specified user to add the specified cert.
    30  func Add(user model.User, cert model.Cert) {
    31  	sess, err := cmd.Start("deis certs:add %s %s %s", &user, cert.Name, cert.CertPath, cert.KeyPath)
    32  	Eventually(sess).Should(Say("Adding SSL endpoint..."))
    33  	Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("done"))
    34  	Expect(err).NotTo(HaveOccurred())
    35  	Eventually(sess).Should(Exit(0))
    36  	Eventually(List(user).Wait().Out.Contents()).Should(ContainSubstring(cert.Name))
    37  }
    38  
    39  // Remove executes `deis certs:remove` as the specified user to remove the specified cert.
    40  func Remove(user model.User, cert model.Cert) {
    41  	sess, err := cmd.Start("deis certs:remove %s", &user, cert.Name)
    42  	Eventually(sess).Should(Say("Removing %s...", cert.Name))
    43  	Eventually(sess).Should(Say("done"))
    44  	Expect(err).NotTo(HaveOccurred())
    45  	Eventually(sess).Should(Exit(0))
    46  	Eventually(List(user).Wait().Out.Contents()).ShouldNot(ContainSubstring(cert.Name))
    47  }
    48  
    49  // Attach executes `deis certs:attach` as the specified user to attach the specified cert to the
    50  // specified domain.
    51  func Attach(user model.User, cert model.Cert, domain string) {
    52  	sess, err := cmd.Start("deis certs:attach %s %s", &user, cert.Name, domain)
    53  	// Explicitly build literal substring since 'domain' may be a wildcard domain ('*.foo.com') and
    54  	// we don't want Gomega interpreting this string as a regexp
    55  	Eventually(sess.Wait().Out.Contents()).Should(ContainSubstring(fmt.Sprintf("Attaching certificate %s to domain %s...", cert.Name, domain)))
    56  	Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("done"))
    57  	Expect(err).NotTo(HaveOccurred())
    58  	Eventually(sess).Should(Exit(0))
    59  }
    60  
    61  // Detatch executes `deis certs:detach` as the specified user to detach the specified cert from
    62  // the specified domain.
    63  func Detach(user model.User, cert model.Cert, domain string) {
    64  	sess, err := cmd.Start("deis certs:detach %s %s", &user, cert.Name, domain)
    65  	// Explicitly build literal substring since 'domain' may be a wildcard domain ('*.foo.com') and
    66  	// we don't want Gomega interpreting this string as a regexp
    67  	Eventually(sess.Wait().Out.Contents()).Should(ContainSubstring(fmt.Sprintf("Detaching certificate %s from domain %s...", cert.Name, domain)))
    68  	Eventually(sess, settings.MaxEventuallyTimeout).Should(Say("done"))
    69  	Expect(err).NotTo(HaveOccurred())
    70  	Eventually(sess).Should(Exit(0))
    71  }
    72  
    73  // Info executes `deis certs:info` as the specified user to retrieve information about the
    74  // specified cert.
    75  func Info(user model.User, cert model.Cert) *Session {
    76  	sess, err := cmd.Start("deis certs:info %s", &user, cert.Name)
    77  	Eventually(sess).Should(Say("=== %s Certificate", cert.Name))
    78  	Expect(err).NotTo(HaveOccurred())
    79  	Eventually(sess).Should(Exit(0))
    80  	return sess
    81  }