@@ -9,11 +9,11 @@ import (
99 "path"
1010
1111 . "github.com/onsi/ginkgo"
12- . "github.com/onsi/ginkgo/config"
1312
1413 . "github.com/onsi/gomega"
1514
1615 "testing"
16+ "time"
1717)
1818
1919const (
@@ -52,15 +52,14 @@ var _ = BeforeSuite(func() {
5252 // register the test-admin user
5353 register (url , testAdminUser , testAdminPassword , testAdminEmail )
5454 // verify this user is an admin by running a privileged command
55- _ , err = execute ("deis users:list" )
56- Expect (err ).NotTo (HaveOccurred ())
55+ Expect (cmd ("deis users:list" )).To (BeASuccessfulCmd ())
5756
5857 // register the test user and add a key
5958 register (url , testUser , testPassword , testEmail )
6059 createKey ("deis-test" )
61- output , err := execute ( "deis keys:add ~/.ssh/deis-test.pub" )
62- Expect ( err ). NotTo ( HaveOccurred ())
63- Expect ( output ). To ( ContainSubstring ( "Uploading deis-test.pub to deis... done" ))
60+ Expect ( cmd ( "deis keys:add ~/.ssh/deis-test.pub" )). To ( BeASuccessfulCmdWithOutput (
61+ ContainSubstring ( "Uploading deis-test.pub to deis... done" ),
62+ ))
6463})
6564
6665var _ = AfterSuite (func () {
@@ -72,36 +71,39 @@ var _ = AfterSuite(func() {
7271})
7372
7473func register (url , username , password , email string ) {
75- cmd := "deis register %s --username=%s --password=%s --email=%s"
76- output , err := execute (cmd , url , username , password , email )
77- Expect (err ).NotTo (HaveOccurred ())
78- Expect (output ).To (SatisfyAll (
74+ Expect (cmd ("deis register %s --username=%s --password=%s --email=%s" , url , username , password , email )).To (BeASuccessfulCmdWithOutput (
7975 ContainSubstring ("Registered %s" , username ),
80- ContainSubstring ("Logged in as %s" , username )))
76+ ContainSubstring ("Logged in as %s" , username ),
77+ ))
8178}
8279
8380func cancel (url , username , password string ) {
8481 // log in to the account
8582 login (url , username , password )
8683
8784 // cancel the account
88- cmd := "deis auth:cancel --username=%s --password=%s --yes"
89- output , err := execute (cmd , username , password )
90- Expect (err ).NotTo (HaveOccurred ())
91- Expect (output ).To (ContainSubstring ("Account cancelled" ))
85+ Expect (cmd ("deis auth:cancel --username=%s --password=%s --yes" , username , password )).To (BeASuccessfulCmdWithOutput (
86+ ContainSubstring ("Account cancelled" ),
87+ ))
9288}
9389
9490func login (url , user , password string ) {
95- cmd := "deis login %s --username=%s --password=%s"
96- output , err := execute (cmd , url , user , password )
97- Expect (err ).NotTo (HaveOccurred ())
98- Expect (output ).To (ContainSubstring ("Logged in as %s" , user ))
91+ Expect (cmd ("deis login %s --username=%s --password=%s" , url , user , password )).To (BeASuccessfulCmdWithOutput (
92+ ContainSubstring ("Logged in as %s" , user ),
93+ ))
9994}
10095
10196func logout () {
102- output , err := execute ("deis auth:logout" )
103- Expect (err ).NotTo (HaveOccurred ())
104- Expect (output ).To (Equal ("Logged out\n " ))
97+ Expect (cmd ("deis auth:logout" )).To (BeASuccessfulCmdWithOutput (
98+ Equal ("Logged out\n " ),
99+ ))
100+ }
101+
102+ // execute executes the command generated by fmt.Sprintf(cmdLine, args...) and returns its output as a cmdOut structure.
103+ // this structure can then be matched upon using the SucceedWithOutput matcher below
104+ func execute (cmdLine string , args ... interface {}) (string , error ) {
105+ c := cmd (cmdLine , args ... )
106+ return c .stdout , c .err
105107}
106108
107109func createKey (name string ) {
@@ -114,13 +116,10 @@ func createKey(name string) {
114116 path := path .Join (home , ".ssh" , name )
115117 // create the key under ~/.ssh/<name> if it doesn't already exist
116118 if _ , err := os .Stat (path ); os .IsNotExist (err ) {
117- cmd := "ssh-keygen -q -t rsa -b 4096 -C %s -f %s -N ''"
118- _ , err := execute (cmd , name , path )
119- Expect (err ).NotTo (HaveOccurred ())
119+ Expect (cmd ("ssh-keygen -q -t rsa -b 4096 -C %s -f %s -N ''" , name , path )).To (BeASuccessfulCmd ())
120120 }
121121 // add the key to ssh-agent
122- _ , err := execute ("eval $(ssh-agent) && ssh-add %s" , path )
123- Expect (err ).NotTo (HaveOccurred ())
122+ Expect (cmd ("eval $(ssh-agent) && ssh-add %s" , path )).To (BeASuccessfulCmd ())
124123}
125124
126125func getController () string {
0 commit comments