/
application_descriptor_test.go
118 lines (88 loc) · 4.18 KB
/
application_descriptor_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
package console_test
import (
"strings"
"testing"
"github.com/eidolon/console"
"github.com/seeruk/assert"
)
func TestDescribeApplication(t *testing.T) {
t.Run("should show the application logo if there is one", func(t *testing.T) {
application := console.NewApplication("eidolon/console", "1.2.3+testing")
application.Logo = "Eidolon Console\n"
result := console.DescribeApplication(application)
assert.True(t, strings.Contains(result, application.Logo), "Expected application logo.")
})
t.Run("should show the application name", func(t *testing.T) {
application := console.NewApplication("eidolon/console", "1.2.3+testing")
result := console.DescribeApplication(application)
assert.True(t, strings.Contains(result, application.Name), "Expected application name.")
})
t.Run("should show the application version", func(t *testing.T) {
application := console.NewApplication("eidolon/console", "1.2.3+testing")
result := console.DescribeApplication(application)
assert.True(t, strings.Contains(result, application.Version), "Expected application version.")
})
t.Run("should show the application usage", func(t *testing.T) {
application := console.NewApplication("eidolon/console", "1.2.3+testing")
application.UsageName = "eidolon_console_binary"
usage := application.UsageName + " COMMAND [OPTIONS...] [ARGUMENTS...]"
result := console.DescribeApplication(application)
assert.True(t, strings.Contains(result, "USAGE:"), "Expected application usage title.")
assert.True(t, strings.Contains(result, usage), "Expected application usage.")
})
t.Run("should show the application options if there are any", func(t *testing.T) {
// @TODO: Update with global options implementation.
//var s1 string
//
//application := console.NewApplication("eidolon/console", "1.2.3+testing")
//application.Configure = func(definition *console.Definition) {
// definition.AddOption(console.OptionDefinition{
// Value: parameters.NewStringValue(&s1),
// Spec: "--s1",
// Desc: "S1 option for testing.",
// })
//}
//
//result := console.DescribeApplication(application)
//
//assert.True(t, strings.Contains(result, "OPTIONS:"), "Expected application options title.")
//assert.True(t, strings.Contains(result, "-h"), "Expected application options.")
//assert.True(t, strings.Contains(result, "--help"), "Expected application options.")
//assert.True(t, strings.Contains(result, "--s1"), "Expected application options.")
})
t.Run("should show the application commands if there are any", func(t *testing.T) {
application := console.NewApplication("eidolon/console", "1.2.3+testing")
application.AddCommands([]*console.Command{
{
Name: "foo-cmd",
},
{
Name: "bar-cmd",
},
})
result := console.DescribeApplication(application)
assert.True(t, strings.Contains(result, "COMMANDS:"), "Expected application commands title.")
assert.True(t, strings.Contains(result, "foo-cmd"), "Expected application commands.")
assert.True(t, strings.Contains(result, "bar-cmd"), "Expected application commands.")
})
t.Run("should not show the commands title if there are no commands", func(t *testing.T) {
application := console.NewApplication("eidolon/console", "1.2.3+testing")
application.Logo = "Eidolon Console\n"
result := console.DescribeApplication(application)
assert.False(t, strings.Contains(result, "COMMANDS:"), "Expected no commands title.")
})
t.Run("should show the application help if there is any", func(t *testing.T) {
help := "This is some application help right here. Lorem ipsum dolor sit amet."
application := console.NewApplication("eidolon/console", "1.2.3+testing")
application.Help = help
result := console.DescribeApplication(application)
assert.True(t, strings.Contains(result, "HELP:"), "Expected help title.")
assert.True(t, strings.Contains(result, help), "Expected help.")
})
t.Run("should not show the help title if there is no application help", func(t *testing.T) {
application := console.NewApplication("eidolon/console", "1.2.3+testing")
application.Logo = "Eidolon Console\n"
result := console.DescribeApplication(application)
assert.False(t, strings.Contains(result, "HELP:"), "Expected no help title.")
})
}