@@ -20,7 +20,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
20
SOFTWARE.
21
21
*/
22
22
23
- package cmd
23
+ package shell
24
24
25
25
import (
26
26
"bytes"
@@ -32,45 +32,45 @@ import (
32
32
)
33
33
34
34
func Test_is_in_path_for_a_valid_command (t * testing.T ) {
35
- assert .True (t , New ("ls" ).IsInPath ())
35
+ assert .True (t , NewCommand ("ls" ).IsInPath ())
36
36
}
37
37
38
38
func Test_is_in_path_for_an_invalid_command (t * testing.T ) {
39
- assert .False (t , New ("unknown-command" ).IsInPath ())
39
+ assert .False (t , NewCommand ("unknown-command" ).IsInPath ())
40
40
}
41
41
42
42
func Test_get_full_path_for_a_valid_command (t * testing.T ) {
43
- base := filepath .Base (New ("ls" ).GetFullPath ())
43
+ base := filepath .Base (NewCommand ("ls" ).GetFullPath ())
44
44
assert .Equal (t , strings .TrimSuffix (base , ".exe" ), "ls" )
45
45
}
46
46
47
47
func Test_get_full_path_for_an_invalid_command (t * testing.T ) {
48
- assert .Zero (t , New ("unknown-command" ).GetFullPath ())
48
+ assert .Zero (t , NewCommand ("unknown-command" ).GetFullPath ())
49
49
}
50
50
51
51
func Test_run_valid_command_with_initial_parameters (t * testing.T ) {
52
- output , err := New ("echo" , "hello world!" ).Run ()
52
+ output , err := NewCommand ("echo" , "hello world!" ).Run ()
53
53
assert .NoError (t , err )
54
54
trimmed := string (bytes .TrimRight (output , "\r \n " ))
55
55
assert .Equal (t , "hello world!" , trimmed )
56
56
}
57
57
58
58
func Test_run_valid_command_with_additional_parameters (t * testing.T ) {
59
- output , err := New ("echo" ).Run ("hello world!" )
59
+ output , err := NewCommand ("echo" ).Run ("hello world!" )
60
60
assert .NoError (t , err )
61
61
trimmed := string (bytes .TrimRight (output , "\r \n " ))
62
62
assert .Equal (t , "hello world!" , trimmed )
63
63
}
64
64
65
65
func Test_run_invalid_command (t * testing.T ) {
66
- output , err := New ("unknown-command" ).Run ()
66
+ output , err := NewCommand ("unknown-command" ).Run ()
67
67
assert .Error (t , err )
68
68
assert .Zero (t , output )
69
69
}
70
70
71
71
func Test_trace_valid_command_with_initial_parameters (t * testing.T ) {
72
72
sniffer := report .NewSniffer ()
73
- err := New ("echo" , "hello world!" ).Trace ()
73
+ err := NewCommand ("echo" , "hello world!" ).Trace ()
74
74
sniffer .Stop ()
75
75
assert .NoError (t , err )
76
76
assert .Equal (t , 1 , sniffer .GetMatchCount ())
@@ -80,7 +80,7 @@ func Test_trace_valid_command_with_initial_parameters(t *testing.T) {
80
80
81
81
func Test_trace_valid_command_with_additional_parameters (t * testing.T ) {
82
82
sniffer := report .NewSniffer ()
83
- err := New ("echo" ).Trace ("hello world!" )
83
+ err := NewCommand ("echo" ).Trace ("hello world!" )
84
84
sniffer .Stop ()
85
85
assert .NoError (t , err )
86
86
assert .Equal (t , 1 , sniffer .GetMatchCount ())
@@ -90,47 +90,47 @@ func Test_trace_valid_command_with_additional_parameters(t *testing.T) {
90
90
91
91
func Test_trace_invalid_command (t * testing.T ) {
92
92
sniffer := report .NewSniffer ()
93
- err := New ("unknown-command" ).Trace ()
93
+ err := NewCommand ("unknown-command" ).Trace ()
94
94
sniffer .Stop ()
95
95
assert .Error (t , err )
96
96
assert .Equal (t , 0 , sniffer .GetMatchCount ())
97
97
}
98
98
99
99
func Test_run_pipe_valid_commands_with_initial_parameters (t * testing.T ) {
100
- output , err := New ("echo" , "hello\t world!" ).RunAndPipe (
101
- New ("cut" , "-f" , "1" ))
100
+ output , err := NewCommand ("echo" , "hello\t world!" ).RunAndPipe (
101
+ NewCommand ("cut" , "-f" , "1" ))
102
102
assert .NoError (t , err )
103
103
trimmed := string (bytes .TrimRight (output , "\r \n " ))
104
104
assert .Equal (t , "hello" , trimmed )
105
105
}
106
106
107
107
func Test_run_pipe_valid_commands_with_additional_parameters (t * testing.T ) {
108
- output , err := New ("echo" ).RunAndPipe (
109
- New ("cut" , "-f" , "1" ),
108
+ output , err := NewCommand ("echo" ).RunAndPipe (
109
+ NewCommand ("cut" , "-f" , "1" ),
110
110
"hello\t world!" )
111
111
assert .NoError (t , err )
112
112
trimmed := string (bytes .TrimRight (output , "\r \n " ))
113
113
assert .Equal (t , "hello" , trimmed )
114
114
}
115
115
116
116
func Test_run_pipe_with_first_command_invalid (t * testing.T ) {
117
- output , err := New ("unknown-command" ).RunAndPipe (
118
- New ("cut" , "-f" , "1" ))
117
+ output , err := NewCommand ("unknown-command" ).RunAndPipe (
118
+ NewCommand ("cut" , "-f" , "1" ))
119
119
assert .Error (t , err )
120
120
assert .Zero (t , output )
121
121
}
122
122
123
123
func Test_run_pipe_with_second_command_invalid (t * testing.T ) {
124
- output , err := New ("echo" ).RunAndPipe (
125
- New ("unknown-command" ))
124
+ output , err := NewCommand ("echo" ).RunAndPipe (
125
+ NewCommand ("unknown-command" ))
126
126
assert .Error (t , err )
127
127
assert .Zero (t , output )
128
128
}
129
129
130
130
func Test_trace_pipe_valid_commands_with_initial_parameters (t * testing.T ) {
131
131
sniffer := report .NewSniffer ()
132
- err := New ("echo" , "hello\t world!" ).TraceAndPipe (
133
- New ("cut" , "-f" , "1" ))
132
+ err := NewCommand ("echo" , "hello\t world!" ).TraceAndPipe (
133
+ NewCommand ("cut" , "-f" , "1" ))
134
134
sniffer .Stop ()
135
135
assert .NoError (t , err )
136
136
assert .Equal (t , 1 , sniffer .GetMatchCount ())
@@ -140,8 +140,8 @@ func Test_trace_pipe_valid_commands_with_initial_parameters(t *testing.T) {
140
140
141
141
func Test_trace_pipe_valid_commands_with_additional_parameters (t * testing.T ) {
142
142
sniffer := report .NewSniffer ()
143
- err := New ("echo" ).TraceAndPipe (
144
- New ("cut" , "-f" , "1" ),
143
+ err := NewCommand ("echo" ).TraceAndPipe (
144
+ NewCommand ("cut" , "-f" , "1" ),
145
145
"hello\t world!" )
146
146
sniffer .Stop ()
147
147
assert .NoError (t , err )
@@ -152,17 +152,17 @@ func Test_trace_pipe_valid_commands_with_additional_parameters(t *testing.T) {
152
152
153
153
func Test_trace_pipe_with_first_command_invalid (t * testing.T ) {
154
154
sniffer := report .NewSniffer ()
155
- err := New ("unknown-command" ).TraceAndPipe (
156
- New ("cut" , "-f" , "1" ))
155
+ err := NewCommand ("unknown-command" ).TraceAndPipe (
156
+ NewCommand ("cut" , "-f" , "1" ))
157
157
sniffer .Stop ()
158
158
assert .Error (t , err )
159
159
assert .Equal (t , 0 , sniffer .GetMatchCount ())
160
160
}
161
161
162
162
func Test_trace_pipe_with_second_command_invalid (t * testing.T ) {
163
163
sniffer := report .NewSniffer ()
164
- err := New ("echo" ).TraceAndPipe (
165
- New ("unknown-command" ))
164
+ err := NewCommand ("echo" ).TraceAndPipe (
165
+ NewCommand ("unknown-command" ))
166
166
sniffer .Stop ()
167
167
assert .Error (t , err )
168
168
assert .Equal (t , 0 , sniffer .GetMatchCount ())
0 commit comments