Skip to content

Commit 11d45c6

Browse files
committed
Merge pull request #184 from arschles/more-better-tests-2
Test Improvements II
2 parents 26a2b1d + ecfc8ad commit 11d45c6

4 files changed

Lines changed: 51 additions & 38 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ docs/docs.zip
2929
docs/dummy.sqlite3
3030
manifests/*.tmp.yml
3131
_tests/_tests.test
32+
_tests/example-*/
3233

3334
# coverage reports
3435
.coverage

_tests/auth_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ var _ = Describe("Auth", func() {
5656
It("regenerates the token for a specified user", func() {
5757
output, err := execute("deis auth:regenerate -u %s", testUser)
5858
Expect(err).NotTo(HaveOccurred())
59-
Expect(output).To(ContainSubstring("???"))
59+
Expect(output).To(ContainSubstring("Token Regenerated"))
6060
})
6161

6262
It("regenerates the token for all users", func() {
6363
output, err := execute("deis auth:regenerate --all")
6464
Expect(err).NotTo(HaveOccurred())
65-
Expect(output).To(ContainSubstring("???"))
65+
Expect(output).To(ContainSubstring("Token Regenerated"))
6666
})
6767
})
6868
})

_tests/keys_test.go

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package _tests_test
22

33
import (
44
"os"
5+
"os/user"
6+
"path"
57

68
. "github.com/onsi/ginkgo"
79
. "github.com/onsi/gomega"
@@ -10,38 +12,40 @@ import (
1012
var _ = Describe("Keys", func() {
1113
key := testUser
1214

13-
BeforeEach(func() {
14-
addKey(key)
15-
})
16-
17-
AfterEach(func() {
18-
// remove the generated ssh key
19-
key := testUser
20-
execute("deis keys:remove %s", key)
21-
err := os.Remove(key)
22-
Expect(err).NotTo(HaveOccurred())
23-
err = os.Remove(key + ".pub")
24-
Expect(err).NotTo(HaveOccurred())
25-
})
15+
Context("when logged in as a normal user", func() {
16+
BeforeEach(func() {
17+
login(url, testUser, testPassword)
18+
createKey(testUser)
19+
})
2620

27-
Context("with a new key", func() {
21+
AfterEach(func() {
22+
// remove the generated ssh key
23+
var home string
24+
if user, err := user.Current(); err != nil {
25+
home = "~"
26+
} else {
27+
home = user.HomeDir
28+
}
29+
path := path.Join(home, ".ssh", testUser)
30+
err := os.Remove(path)
31+
Expect(err).NotTo(HaveOccurred())
32+
err = os.Remove(path + ".pub")
33+
Expect(err).NotTo(HaveOccurred())
34+
})
2835

29-
It("can add the key", func() {
30-
output, err := execute("deis keys:add %s.pub", key)
36+
It("can add, list, and remove a key", func() {
37+
output, err := execute("deis keys:add ~/.ssh/%s.pub", key)
3138
Expect(err).NotTo(HaveOccurred())
3239
Expect(output).To(ContainSubstring("Uploading %s.pub to deis... done", key))
3340
output, err = execute("deis keys:list")
3441
Expect(err).NotTo(HaveOccurred())
35-
Expect(output).To(ContainSubstring("%s@deis.com", key))
36-
})
37-
38-
It("can remove the key", func() {
39-
output, err := execute("deis keys:remove %s@deis.com", key)
42+
Expect(output).To(ContainSubstring("%s ssh-rsa", key))
43+
output, err = execute("deis keys:remove %s", key)
4044
Expect(err).NotTo(HaveOccurred())
41-
Expect(output).To(ContainSubstring("Removing %s@deis.com SSH Key... done", key))
45+
Expect(output).To(ContainSubstring("Removing %s SSH Key... done", key))
4246
output, err = execute("deis keys")
4347
Expect(err).NotTo(HaveOccurred())
44-
Expect(output).NotTo(ContainSubstring("%s@deis.com", key))
48+
Expect(output).NotTo(ContainSubstring("%s ssh-rsa", key))
4549
})
4650
})
4751
})

_tests/tests_suite_test.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import (
1717
"testing"
1818
)
1919

20+
const (
21+
deisWorkflowServiceHost = "DEIS_WORKFLOW_SERVICE_HOST"
22+
deisWorkflowServicePort = "DEIS_WORKFLOW_SERVICE_PORT"
23+
)
24+
2025
func init() {
2126
rand.Seed(GinkgoConfig.RandomSeed)
2227
}
@@ -41,19 +46,22 @@ var (
4146
)
4247

4348
var _ = BeforeSuite(func() {
44-
workflowHost := os.Getenv("DEIS_WORKFLOW_SERVICE_HOST")
45-
Expect(workflowHost).ShouldNot(BeEmpty())
4649
// use the "deis" executable in the search $PATH
4750
_, err := exec.LookPath("deis")
4851
Expect(err).NotTo(HaveOccurred())
4952

5053
// register the test-admin user
5154
register(url, testAdminUser, testAdminPassword, testAdminEmail)
52-
// TODO: verify that this user is actually an admin
55+
// verify this user is an admin by running a privileged command
56+
_, err = execute("deis users:list")
57+
Expect(err).NotTo(HaveOccurred())
5358

5459
// register the test user and add a key
5560
register(url, testUser, testPassword, testEmail)
56-
addKey("deis-test")
61+
createKey("deis-test")
62+
output, err := execute("deis keys:add ~/.ssh/deis-test.pub")
63+
Expect(err).NotTo(HaveOccurred())
64+
Expect(output).To(ContainSubstring("Uploading deis-test.pub to deis... done"))
5765
})
5866

5967
var _ = AfterSuite(func() {
@@ -108,7 +116,7 @@ func execute(cmdLine string, args ...interface{}) (string, error) {
108116
return stdout.String(), nil
109117
}
110118

111-
func addKey(name string) {
119+
func createKey(name string) {
112120
var home string
113121
if user, err := user.Current(); err != nil {
114122
home = "~"
@@ -118,24 +126,24 @@ func addKey(name string) {
118126
path := path.Join(home, ".ssh", name)
119127
// create the key under ~/.ssh/<name> if it doesn't already exist
120128
if _, err := os.Stat(path); os.IsNotExist(err) {
121-
cmd := "ssh-keygen -q -t rsa -b 4096 -C otto.test@deis.com -f %s -N ''"
122-
_, err := execute(cmd, path)
129+
cmd := "ssh-keygen -q -t rsa -b 4096 -C %s -f %s -N ''"
130+
_, err := execute(cmd, name, path)
123131
Expect(err).NotTo(HaveOccurred())
124132
}
125133
// add the key to ssh-agent
126134
_, err := execute("eval $(ssh-agent) && ssh-add %s", path)
127135
Expect(err).NotTo(HaveOccurred())
128-
// add the public key to deis (assumes the user is logged in)
129-
_, err = execute("deis keys:add %s.pub", path)
130-
Expect(err).NotTo(HaveOccurred())
131136
}
132137

133138
func getController() string {
134-
host := os.Getenv("DEIS_WORKFLOW_SERVICE_HOST")
139+
host := os.Getenv(deisWorkflowServiceHost)
135140
if host == "" {
136-
panic("DEIS_WORKFLOW_SERVICE_HOST isn't set")
141+
panicStr := fmt.Sprintf(`Set %s to the workflow controller hostname for tests, such as:
142+
143+
$ %s=deis.10.245.1.3.xip.io make test-integration`, deisWorkflowServiceHost, deisWorkflowServiceHost)
144+
panic(panicStr)
137145
}
138-
port := os.Getenv("DEIS_WORKFLOW_SERVICE_PORT")
146+
port := os.Getenv(deisWorkflowServicePort)
139147
switch port {
140148
case "443":
141149
return "https://" + host

0 commit comments

Comments
 (0)