/
demo_test.go
69 lines (55 loc) 路 1.25 KB
/
demo_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
package demo_test
import (
"os"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/saschagrunert/demo"
"github.com/urfave/cli/v2"
)
var _ = t.Describe("Demo", func() {
It("should succeed to run", func() {
// Given
os.Args = []string{"demo"}
sut := demo.New()
// When
sut.Run()
})
It("should succeed to run with example", func() {
// Given
os.Args = []string{
"demo", "--auto", "--auto-timeout=0", "--immediate", "-0",
}
example := func() *demo.Run {
r := demo.NewRun(
"Title",
"Some additional",
"multiline description",
)
r.Step(demo.S(
"This is a possible",
"description of the command",
"to be executed",
), demo.S("echo hello world"))
r.Step(nil, demo.S("echo without description"))
r.Step(demo.S("Just a description without a command"), nil)
return r
}
sut := demo.New()
sut.Add(example(), "title", "description")
type success struct{ setup, cleanup bool }
succeed := &success{}
sut.Setup(func(*cli.Context) error {
succeed.setup = true
return nil
})
sut.Cleanup(func(*cli.Context) error {
succeed.cleanup = true
return nil
})
// When
sut.Run()
// Then
Expect(succeed.setup).To(BeTrue())
Expect(succeed.cleanup).To(BeTrue())
})
})