-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommand_test.go
More file actions
118 lines (113 loc) · 2.53 KB
/
command_test.go
File metadata and controls
118 lines (113 loc) · 2.53 KB
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 tui
import (
"testing"
)
func TestNoArgsPass(t *testing.T) {
tmpc := Command{
Title: "No Args",
Cli: "./sampleapp/testcommands/waitqok.sh",
Description: "test of running a Command with out arguments",
Success: "Yey it works",
Execute: OSCmdHandler,
}
ch := make(chan string)
go tmpc.Execute(&tmpc, ch)
for ok := true; ok; {
_, ok = <-ch
}
if tmpc.Error != nil {
t.Log(tmpc.Error)
t.Fail()
}
}
func TestNoArgsFail(t *testing.T) {
tmpc := Command{
Title: "foo",
Cli: "./sampleapp/testcommands/args.sh",
Description: "foo",
Success: "foo",
Execute: OSCmdHandler,
}
ch := make(chan string)
go tmpc.Execute(&tmpc, ch)
for ok := true; ok; {
_, ok = <-ch
}
if tmpc.Error == nil {
t.Log(tmpc.Error)
t.Fail()
}
}
func TestArgsPass(t *testing.T) {
tmpc := Command{
Title: "Args CLI",
Cli: "./sampleapp/testcommands/args.sh",
Description: "test of running a tui.Command with arguments",
Args: []Argument{
Argument{
Description: "Would you like to set this is a sample flag bool?",
Title: "Sample Flag Bool",
IsBoolean: true,
Name: "first",
IsFlag: true,
Valuebool: true,
},
Argument{
Description: "This is a sample value flag",
Title: "Sample Flag with value",
Name: "second",
IsFlag: true,
Value: "foo",
},
Argument{
Description: "Would you like to set this is a sample bool?",
Title: "Sample Bool",
IsBoolean: true,
Name: "third",
Valuebool: true,
},
},
Success: "Yey it works",
Fail: "oh, it didnt work.",
Execute: OSCmdHandler,
}
ch := make(chan string)
go tmpc.Execute(&tmpc, ch)
for ok := true; ok; {
_, ok = <-ch
}
if tmpc.Error != nil {
t.Log(tmpc.Error)
t.Fail()
}
}
func TestArgsEnvPass(t *testing.T) {
tmpc := Command{
Title: "Args Envar",
Cli: "./sampleapp/testcommands/env.sh",
Description: "test of running a command with arguments via envar",
Args: []Argument{
Argument{
Description: "Would you like to set this is a sample Envar bool?",
Title: "Sample Envar Bool",
IsBoolean: true,
Name: "first",
IsFlag: true,
Envar: "FIRSTTEST",
Valuebool: true,
},
},
Success: "Yey it works",
Fail: "oh, it didnt work.",
Execute: OSCmdHandler,
}
ch := make(chan string)
go tmpc.Execute(&tmpc, ch)
for ok := true; ok; {
_, ok = <-ch
}
if tmpc.Error != nil {
t.Log(tmpc.Error)
t.Fail()
}
}