-
Notifications
You must be signed in to change notification settings - Fork 18
/
server_test.go
89 lines (68 loc) · 2.21 KB
/
server_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main_test
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"
)
var goodConfig = []byte(`---
environments:
- name: sandbox
service_now_endpoint: https://allstateuat.service-now.com/u_platform_integration.do?SOAP
domain: platformtest.allstate.com
allow_page: false
authenticate: false
skip_ssl: true
foundations:
- https://api.cf.sandbox-mpn.ro98.allstate.com
- https://api.cf.sandbox-mpn.ro99.allstate.com
`)
var badTestConfig = []byte(`---
environments:
- name: sandbox
`)
var _ = Describe("Server", func() {
var (
session *gexec.Session
err error
)
AfterEach(func() {
session.Terminate()
})
Context("when a log level is not specified", func() {
It("uses the default log level ", func() {
configLocation := fmt.Sprintf("%s/config.yml", path.Dir(pathToCLI))
Expect(ioutil.WriteFile(configLocation, goodConfig, 0777)).To(Succeed())
level := os.Getenv("DEPLOYADACTYL_LOGLEVEL")
os.Unsetenv("DEPLOYADACTYL_LOGLEVEL")
Expect(err).ToNot(HaveOccurred())
session, err = gexec.Start(exec.Command(pathToCLI, "-config", configLocation), GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())
Eventually(session.Out).Should(gbytes.Say("log level"))
Eventually(session.Out).Should(gbytes.Say("DEBUG"))
os.Setenv("DEPLOYADACTYL_LOGLEVEL", level)
})
})
Context("when log level is invalid", func() {
It("throws an error", func() {
level := os.Getenv("DEPLOYADACTYL_LOGLEVEL")
Expect(os.Setenv("DEPLOYADACTYL_LOGLEVEL", "tanystropheus")).To(Succeed())
session, err = gexec.Start(exec.Command(pathToCLI), GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())
Eventually(session.Err).Should(gbytes.Say("invalid log level"))
os.Setenv("DEPLOYADACTYL_LOGLEVEL", level)
})
})
Context("when an invalid config path is specified", func() {
It("throws an error", func() {
session, err = gexec.Start(exec.Command(pathToCLI, "-config", "./gorgosaurus.yml"), GinkgoWriter, GinkgoWriter)
Expect(err).ToNot(HaveOccurred())
Eventually(session.Out).Should(gbytes.Say("no such file or directory"))
})
})
})