-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommandline_test.go
206 lines (193 loc) · 6.68 KB
/
commandline_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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
Copyright 2017 Ontario Systems
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package isclib_test
import (
"os"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/ontariosystems/isclib/v2"
)
var _ = Describe("Commands", func() {
var (
origCControlCommand string
origCSessionCommand string
origIrisCommand string
origPath string
tempCControlCommand *os.File
tempCSessionCommand *os.File
tempIrisCommand *os.File
)
Context("AvailableCommands", func() {
BeforeEach(func() {
origPath = os.Getenv("PATH")
os.Setenv("PATH", origPath+":/tmp")
origCControlCommand = isclib.CControlPath()
isclib.SetCControlPath("/somepath/ccontrol")
origCSessionCommand = isclib.CSessionPath()
isclib.SetCSessionPath("/somepath/csession")
origIrisCommand = isclib.IrisPath()
isclib.SetIrisPath("/somepath/iris")
})
AfterEach(func() {
os.Setenv("PATH", origPath)
isclib.SetCControlPath(origCControlCommand)
isclib.SetCSessionPath(origCSessionCommand)
isclib.SetIrisPath(origIrisCommand)
})
Context("No ISC executables", func() {
It("should return NoCommand", func() {
commands := isclib.AvailableCommands()
Expect(commands).To(Equal(isclib.NoCommand), "no command")
Expect(commands.Has(isclib.CControlCommand)).To(BeFalse())
Expect(commands.Has(isclib.CSessionCommand)).To(BeFalse())
Expect(commands.Has(isclib.IrisCommand)).To(BeFalse())
})
})
Context("With ISC executables", func() {
BeforeEach(func() {
var err error
if tempCControlCommand, err = os.CreateTemp(os.TempDir(), "ccontrol"); err != nil {
panic(err)
}
err = os.Chmod(tempCControlCommand.Name(), 0755)
Expect(err).ToNot(HaveOccurred())
if tempCSessionCommand, err = os.CreateTemp(os.TempDir(), "csession"); err != nil {
panic(err)
}
err = os.Chmod(tempCSessionCommand.Name(), 0755)
Expect(err).ToNot(HaveOccurred())
if tempIrisCommand, err = os.CreateTemp(os.TempDir(), "iris"); err != nil {
panic(err)
}
err = os.Chmod(tempIrisCommand.Name(), 0755)
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
err := os.Remove(tempCControlCommand.Name())
Expect(err).ToNot(HaveOccurred())
err = os.Remove(tempCSessionCommand.Name())
Expect(err).ToNot(HaveOccurred())
err = os.Remove(tempIrisCommand.Name())
Expect(err).ToNot(HaveOccurred())
})
Context("only iris", func() {
BeforeEach(func() {
origIrisCommand = isclib.IrisPath()
isclib.SetIrisPath(tempIrisCommand.Name())
})
AfterEach(func() {
isclib.SetIrisPath(origIrisCommand)
})
It("should return only iris", func() {
commands := isclib.AvailableCommands()
Expect(commands).To(Equal(isclib.IrisCommand), "iris only")
Expect(commands.Has(isclib.CControlCommand)).To(BeFalse())
Expect(commands.Has(isclib.CSessionCommand)).To(BeFalse())
Expect(commands.Has(isclib.IrisCommand)).To(BeTrue())
Expect(commands.Has(isclib.NoCommand)).To(BeFalse())
})
})
Context("only cache commands", func() {
BeforeEach(func() {
origCControlCommand = isclib.CControlPath()
isclib.SetCControlPath(tempCControlCommand.Name())
origCSessionCommand = isclib.CSessionPath()
isclib.SetCSessionPath(tempCSessionCommand.Name())
})
AfterEach(func() {
isclib.SetCControlPath(origCControlCommand)
isclib.SetCSessionPath(origCSessionCommand)
})
It("should return ccontrol and csession", func() {
commands := isclib.AvailableCommands()
Expect(commands).To(Equal(isclib.CControlCommand|isclib.CSessionCommand), "ccontrol and csession")
Expect(commands.Has(isclib.CControlCommand)).To(BeTrue())
Expect(commands.Has(isclib.CSessionCommand)).To(BeTrue())
Expect(commands.Has(isclib.IrisCommand)).To(BeFalse())
Expect(commands.Has(isclib.NoCommand)).To(BeFalse())
})
})
Context("both iris and cache commands", func() {
BeforeEach(func() {
origCControlCommand = isclib.CControlPath()
isclib.SetCControlPath(tempCControlCommand.Name())
origCSessionCommand = isclib.CSessionPath()
isclib.SetCSessionPath(tempCSessionCommand.Name())
origIrisCommand = isclib.IrisPath()
isclib.SetIrisPath(tempIrisCommand.Name())
})
AfterEach(func() {
isclib.SetCControlPath(origCControlCommand)
isclib.SetCSessionPath(origCSessionCommand)
isclib.SetIrisPath(origIrisCommand)
})
It("should return all ISC commands", func() {
commands := isclib.AvailableCommands()
Expect(commands).To(Equal(isclib.CControlCommand|isclib.CSessionCommand|isclib.IrisCommand), "all commands")
Expect(commands.Has(isclib.CControlCommand)).To(BeTrue())
Expect(commands.Has(isclib.CSessionCommand)).To(BeTrue())
Expect(commands.Has(isclib.IrisCommand)).To(BeTrue())
Expect(commands.Has(isclib.NoCommand)).To(BeFalse())
})
})
})
})
Context("Set", func() {
var commands isclib.Commands
BeforeEach(func() {
commands = isclib.NoCommand
})
Context("Adding a command", func() {
It("includes the added command", func() {
commands.Set(isclib.IrisCommand)
Expect(commands.Has(isclib.IrisCommand)).To(BeTrue())
})
})
Context("Adding a command that already exists", func() {
BeforeEach(func() {
commands = isclib.IrisCommand
})
It("still includes the added command", func() {
commands.Set(isclib.IrisCommand)
Expect(commands.Has(isclib.IrisCommand)).To(BeTrue())
})
})
})
Context("Clear", func() {
var commands isclib.Commands
BeforeEach(func() {
commands = isclib.IrisCommand
})
Context("Clearing a command", func() {
It("does not include the cleared command", func() {
commands.Clear(isclib.IrisCommand)
Expect(commands.Has(isclib.IrisCommand)).To(BeFalse())
})
})
})
Context("Has", func() {
var commands isclib.Commands
Context("Has set commands", func() {
BeforeEach(func() {
commands = isclib.CControlCommand | isclib.CSessionCommand
})
It("has the set commands", func() {
Expect(commands.Has(isclib.CControlCommand)).To(BeTrue())
Expect(commands.Has(isclib.CSessionCommand)).To(BeTrue())
})
It("does not have the unset commands", func() {
Expect(commands.Has(isclib.IrisCommand)).To(BeFalse())
})
})
})
})