@@ -24,55 +24,78 @@ package p4
24
24
25
25
import (
26
26
"github.com/murex/tcr/report"
27
+ "github.com/murex/tcr/vcs/cmd"
27
28
"github.com/stretchr/testify/assert"
28
29
"os"
29
30
"strings"
30
31
"testing"
31
32
)
32
33
33
- func skipOnGitHubActions (t * testing.T ) {
34
+ func skipWhenInGitHubActions (t * testing.T ) {
35
+ t .Helper ()
34
36
if os .Getenv ("GITHUB_ACTIONS" ) == "true" {
35
37
t .Skip ("skipped when on GitHub Actions (no p4 environment)" )
36
38
}
37
39
}
38
40
39
41
func Test_is_p4_command_available (t * testing.T ) {
40
- skipOnGitHubActions (t )
42
+ skipWhenInGitHubActions (t )
41
43
assert .True (t , IsP4CommandAvailable ())
42
44
}
43
45
44
46
func Test_get_p4_command_path (t * testing.T ) {
45
- skipOnGitHubActions (t )
47
+ skipWhenInGitHubActions (t )
46
48
assert .NotZero (t , GetP4CommandPath ())
47
49
}
48
50
49
51
func Test_run_p4_command (t * testing.T ) {
50
- skipOnGitHubActions (t )
52
+ skipWhenInGitHubActions (t )
51
53
output , err := runP4Command ("info" )
52
54
assert .NoError (t , err )
53
55
assert .NotZero (t , output )
54
56
}
55
57
56
58
func Test_trace_p4_command (t * testing.T ) {
57
- skipOnGitHubActions (t )
59
+ skipWhenInGitHubActions (t )
58
60
sniffer := report .NewSniffer ()
59
61
err := traceP4Command ("info" )
60
62
sniffer .Stop ()
61
63
assert .NoError (t , err )
62
64
assert .NotZero (t , sniffer .GetMatchCount ())
63
65
}
64
66
67
+ func Test_run_piped_p4_command (t * testing.T ) {
68
+ skipWhenInGitHubActions (t )
69
+ output , err := runPipedP4Command (
70
+ cmd .New ("grep" , "Client name" ),
71
+ "info" )
72
+ assert .NoError (t , err )
73
+ assert .Contains (t , string (output ), "Client name:" )
74
+ }
75
+
76
+ func Test_trace_piped_p4_command (t * testing.T ) {
77
+ skipWhenInGitHubActions (t )
78
+ sniffer := report .NewSniffer ()
79
+ err := tracePipedP4Command (
80
+ cmd .New ("grep" , "Client name" ),
81
+ "info" )
82
+ sniffer .Stop ()
83
+ assert .NoError (t , err )
84
+ assert .Equal (t , 1 , sniffer .GetMatchCount ())
85
+ assert .Contains (t , sniffer .GetAllMatches ()[0 ].Text , "Client name:" )
86
+ }
87
+
65
88
func Test_get_p4_username (t * testing.T ) {
66
- skipOnGitHubActions (t )
89
+ skipWhenInGitHubActions (t )
67
90
assert .NotZero (t , GetP4UserName ())
68
91
}
69
92
70
93
func Test_get_p4_config_value_with_undefined_key (t * testing.T ) {
71
- skipOnGitHubActions (t )
94
+ skipWhenInGitHubActions (t )
72
95
assert .Equal (t , "not set" , getP4ConfigValue ("undefined-config-value" ))
73
96
}
74
97
75
98
func Test_get_p4_command_version (t * testing.T ) {
76
- skipOnGitHubActions (t )
99
+ skipWhenInGitHubActions (t )
77
100
assert .True (t , strings .HasPrefix (GetP4CommandVersion (), "P4/" ))
78
101
}
0 commit comments