1
1
package main
2
2
3
3
import (
4
- "context"
5
4
"fmt"
6
5
"io/ioutil"
7
6
"net/http"
@@ -10,8 +9,6 @@ import (
10
9
"strings"
11
10
"testing"
12
11
13
- "github.com/docker/docker/api/types"
14
- "github.com/docker/docker/client"
15
12
"gopkg.in/yaml.v2"
16
13
"gotest.tools/v3/assert"
17
14
"gotest.tools/v3/icmd"
@@ -25,6 +22,7 @@ const (
25
22
type Config struct {
26
23
Name string `yaml:"name"`
27
24
Command string `yaml:"command"`
25
+ PsCommand string `yaml:"ps_command"`
28
26
GlobalOpts []Opt `yaml:"global_opts,omitempty"`
29
27
Up Verb `yaml:"up,omitempty"`
30
28
Down Verb `yaml:"down,omitempty"`
@@ -61,7 +59,7 @@ func (h TestHelper) TestUpDown(fun func()) {
61
59
h .executeUp (c )
62
60
fun ()
63
61
h .executeDown (c )
64
- h .checkDown ( )
62
+ h .checkCleanUp ( c )
65
63
})
66
64
}
67
65
}
@@ -156,14 +154,17 @@ func (h TestHelper) listFiles(dir string) []string {
156
154
return configFiles
157
155
}
158
156
159
- func (h TestHelper ) checkDown () {
160
- cli , err := client .NewEnvClient ()
161
- assert .NilError (h .T , err )
162
- containers , err := cli .ContainerList (context .Background (), types.ContainerListOptions {
163
- All : true ,
164
- })
165
- assert .NilError (h .T , err )
166
- assert .Assert (h .T , len (containers ) == 0 )
157
+ func (h TestHelper ) checkCleanUp (c * Config ) {
158
+ command := strings .Split (c .PsCommand , " " )
159
+ cmd := icmd .Command (command [0 ], command [1 :]... )
160
+ ret := icmd .RunCmd (cmd ).Assert (h .T , icmd .Success )
161
+ out := strings .Trim (ret .Stdout (), "\n " )
162
+ nLines := len (strings .Split (out , "\n " )) - 1
163
+ assert .Check (
164
+ h .T ,
165
+ 0 == nLines ,
166
+ "Problem checking containers' state. " +
167
+ "There shouldn't be any containers before or after a test." )
167
168
}
168
169
169
170
func (h TestHelper ) getHttpBody (address string ) string {
0 commit comments