-
Notifications
You must be signed in to change notification settings - Fork 19
/
run_test.go
109 lines (89 loc) · 2.25 KB
/
run_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
package demo_test
import (
"flag"
"strings"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/saschagrunert/demo"
"github.com/urfave/cli/v2"
)
var _ = t.Describe("Run", func() {
var (
sut *demo.Run
out *strings.Builder
opts demo.Options
title = "Test Title"
description = []string{"Some", "description"}
)
BeforeEach(func() {
sut = demo.NewRun(title, description...)
Expect(sut).NotTo(BeNil())
out = &strings.Builder{}
err := sut.SetOutput(out)
Expect(err).ToNot(HaveOccurred())
opts = demo.Options{
AutoTimeout: 0,
Auto: true,
Immediate: true,
SkipSteps: 0,
}
})
It("should succeed to run", func() {
// Given
// When
err := sut.RunWithOptions(opts)
// Then
Expect(err).ToNot(HaveOccurred())
Expect(out).To(ContainSubstring(title))
Expect(out).To(ContainSubstring(description[0]))
Expect(out).To(ContainSubstring(description[1]))
})
It("should succeed to run with step", func() {
// Given
const (
descriptionText = "Description Text"
command = "echo 'Some step'"
)
sut.Step(demo.S(descriptionText), demo.S(command))
// When
err := sut.RunWithOptions(opts)
// Then
Expect(err).ToNot(HaveOccurred())
Expect(out).To(ContainSubstring(title))
Expect(out).To(ContainSubstring(description[0]))
Expect(out).To(ContainSubstring(description[1]))
Expect(out).To(ContainSubstring(descriptionText))
Expect(out).To(ContainSubstring(command))
})
It("should succeed to run with step which can fail", func() {
// Given
const (
descriptionText = "Description Text"
command = "exit 1"
)
sut.StepCanFail(demo.S(descriptionText), demo.S(command))
// When
err := sut.RunWithOptions(opts)
// Then
Expect(err).ToNot(HaveOccurred())
})
It("should fail to set nil output", func() {
// Given
// When
err := sut.SetOutput(nil)
// Then
Expect(err).To(HaveOccurred())
})
It("should succeed to run from a cli context", func() {
// Given
app := cli.NewApp()
flagSet := &flag.FlagSet{}
flagSet.Bool(demo.FlagAuto, true, "")
flagSet.Bool(demo.FlagImmediate, true, "")
ctx := cli.NewContext(app, flagSet, nil)
// When
err := sut.Run(ctx)
// Then
Expect(err).ToNot(HaveOccurred())
})
})