-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
94 lines (81 loc) · 2.93 KB
/
main_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
90
91
92
93
94
package main_test
import (
"os/exec"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"
)
var pathToCLI string
var _ = BeforeSuite(func() {
var err error
pathToCLI, err = gexec.Build("github.com/alex-slynko/demoshell")
Expect(err).NotTo(HaveOccurred())
})
var _ = AfterSuite(func() {
gexec.CleanupBuildArtifacts()
})
var _ = Describe("Main", func() {
It("requires an argument", func() {
command := exec.Command(pathToCLI)
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(1))
})
It("checks that file exists", func() {
command := exec.Command(pathToCLI, "fixtures/missing.session")
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(1))
})
It("outputs all commands from the file", func() {
command := exec.Command(pathToCLI, "fixtures/basic.session")
inPipe, err := command.StdinPipe()
Expect(err).NotTo(HaveOccurred())
inPipe.Write([]byte("\n"))
command.Env = append(command.Env, "USER=demo")
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(0))
Expect(session.Out).To(gbytes.Say(`demo.*\$ echo "Hello"`))
})
It("outputs stderr", func() {
command := exec.Command(pathToCLI, "fixtures/stderr.session")
inPipe, err := command.StdinPipe()
Expect(err).NotTo(HaveOccurred())
inPipe.Write([]byte("\n"))
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(0))
Expect(session.Err).To(gbytes.Say(`Hello`))
})
It("waits for user to type", func() {
command := exec.Command(pathToCLI, "fixtures/basic.session")
_, err := command.StdinPipe()
Expect(err).NotTo(HaveOccurred())
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Consistently(session).ShouldNot(gexec.Exit())
Expect(session.Err.Contents()).To(BeEmpty())
})
It("is interruptable by CTRL-C", func() {
command := exec.Command(pathToCLI, "fixtures/basic.session")
_, err := command.StdinPipe()
Expect(err).NotTo(HaveOccurred())
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Consistently(session).ShouldNot(gexec.Exit())
session.Interrupt()
Eventually(session).Should(gexec.Exit())
})
It("does not show symbols that person types", func() {
command := exec.Command(pathToCLI, "fixtures/basic.session")
inPipe, err := command.StdinPipe()
Expect(err).NotTo(HaveOccurred())
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
inPipe.Write([]byte("Should not appear\n"))
Eventually(session).Should(gexec.Exit(0))
Expect(session.Out).NotTo(gbytes.Say("appear"))
})
})