-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands_test.go
46 lines (37 loc) · 1018 Bytes
/
commands_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
package otium
import (
"io"
"os"
"testing"
"github.com/go-quicktest/qt"
)
func setupTestCmdVariables(t *testing.T) (*os.File, func()) {
stdoutRd, stdoutWr, err := os.Pipe()
qt.Assert(t, qt.IsNil(err))
oldStdout := os.Stdout
os.Stdout = stdoutWr
cleanup := func() { os.Stdout = oldStdout }
return stdoutRd, cleanup
}
func TestCmdVariablesEmpty(t *testing.T) {
pcd := NewProcedure(ProcedureOpts{})
stdoutRd, cleanup := setupTestCmdVariables(t)
defer cleanup()
cmdVariables(pcd)
os.Stdout.Close()
buf, err := io.ReadAll(stdoutRd)
qt.Assert(t, qt.IsNil(err))
qt.Assert(t, qt.Equals(string(buf), "no variables\n"))
}
func TestCmdVariablesNotEmpty(t *testing.T) {
pcd := NewProcedure(ProcedureOpts{})
pcd.Put("fruit", "mango")
pcd.Put("amount", "100")
stdoutRd, cleanup := setupTestCmdVariables(t)
defer cleanup()
cmdVariables(pcd)
os.Stdout.Close()
buf, err := io.ReadAll(stdoutRd)
qt.Assert(t, qt.IsNil(err))
qt.Assert(t, qt.Equals(string(buf), "amount (): 100\nfruit (): mango\n"))
}