@@ -19,28 +19,42 @@ func setup(t *testing.T) *ComposeWrapper {
19
19
return w
20
20
}
21
21
22
- func TestCommand (t * testing.T ) {
22
+ func Test_UpAndDown (t * testing.T ) {
23
+
24
+ const composeFileContent = `version: "3.9"
25
+ services:
26
+ busybox:
27
+ image: "alpine:latest"
28
+ container_name: "compose_wrapper_test"`
29
+ const composedContainerName = "compose_wrapper_test"
30
+
23
31
w := setup (t )
24
32
25
- file := "docker-compose-test.yml"
26
- _ , err := w .Up (file , "" , "" , "" )
33
+ dir := os .TempDir ()
34
+
35
+ filePath , err := createComposeFile (dir , composeFileContent )
27
36
if err != nil {
28
37
t .Fatal (err )
29
38
}
30
39
31
- _ , err = w .Down ( file , "" , "" )
40
+ _ , err : = w .Up ( filePath , "" , "test1 " , "" )
32
41
if err != nil {
33
42
t .Fatal (err )
34
43
}
35
44
36
- }
45
+ if ! containerExists (composedContainerName ) {
46
+ t .Fatal ("container should exist" )
47
+ }
37
48
38
- const composeFile = `version: "3.9"
39
- services:
40
- busybox:
41
- image: "alpine:latest"
42
- container_name: "compose_wrapper_test"`
43
- const composedContainerName = "compose_wrapper_test"
49
+ _ , err = w .Down (filePath , "" , "test1" )
50
+ if err != nil {
51
+ t .Fatal (err )
52
+ }
53
+
54
+ if containerExists (composedContainerName ) {
55
+ t .Fatal ("container should be removed" )
56
+ }
57
+ }
44
58
45
59
type composeOptions struct {
46
60
filePath string
@@ -70,34 +84,6 @@ func createComposeFile(dir, composeFileContent string) (string, error) {
70
84
return createFile (dir , "docmer-compose.yml" , composeFileContent )
71
85
}
72
86
73
- // func Test_UpAndDown(t *testing.T) {
74
-
75
- // stack, endpoint := setup(t)
76
-
77
- // w, err := NewComposeStackManager("", nil)
78
- // if err != nil {
79
- // t.Fatalf("Failed creating manager: %s", err)
80
- // }
81
-
82
- // err = w.Up(stack, endpoint)
83
- // if err != nil {
84
- // t.Fatalf("Error calling docker-compose up: %s", err)
85
- // }
86
-
87
- // if !containerExists(composedContainerName) {
88
- // t.Fatal("container should exist")
89
- // }
90
-
91
- // err = w.Down(stack, endpoint)
92
- // if err != nil {
93
- // t.Fatalf("Error calling docker-compose down: %s", err)
94
- // }
95
-
96
- // if containerExists(composedContainerName) {
97
- // t.Fatal("container should be removed")
98
- // }
99
- // }
100
-
101
87
func containerExists (containerName string ) bool {
102
88
cmd := exec .Command ("docker" , "ps" , "-a" , "-f" , fmt .Sprintf ("name=%s" , containerName ))
103
89
0 commit comments