/
cmd.go
39 lines (33 loc) · 940 Bytes
/
cmd.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
package apptest
import (
"os/exec"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func AssertCmdsPartiallyMatch(t *testing.T, expectedCmds []string, actualExecutedCmds []*exec.Cmd) {
notFoundCmds := make([]string, 0, len(expectedCmds))
executedCmdStrs := make([]string, 0, len(actualExecutedCmds))
for _, actualCmd := range actualExecutedCmds {
executedCmdStrs = append(executedCmdStrs, actualCmd.String())
}
for _, expectedCmdStr := range expectedCmds {
cmdFound := false
for _, actualCmdStr := range executedCmdStrs {
if strings.HasSuffix(actualCmdStr, expectedCmdStr) {
cmdFound = true
break
}
}
if !cmdFound {
notFoundCmds = append(notFoundCmds, expectedCmdStr)
}
}
assert.Empty(
t,
notFoundCmds,
"was not able to find following expected commands '%s' in the list of executed commands '%s'",
strings.Join(notFoundCmds, ", "),
strings.Join(executedCmdStrs, ", "),
)
}