Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

Commit 48dc900

Browse files
committed
feat(wrapper): add test
1 parent fb78615 commit 48dc900

File tree

1 file changed

+25
-39
lines changed

1 file changed

+25
-39
lines changed

wrapper_test.go

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,42 @@ func setup(t *testing.T) *ComposeWrapper {
1919
return w
2020
}
2121

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+
2331
w := setup(t)
2432

25-
file := "docker-compose-test.yml"
26-
_, err := w.Up(file, "", "", "")
33+
dir := os.TempDir()
34+
35+
filePath, err := createComposeFile(dir, composeFileContent)
2736
if err != nil {
2837
t.Fatal(err)
2938
}
3039

31-
_, err = w.Down(file, "", "")
40+
_, err := w.Up(filePath, "", "test1", "")
3241
if err != nil {
3342
t.Fatal(err)
3443
}
3544

36-
}
45+
if !containerExists(composedContainerName) {
46+
t.Fatal("container should exist")
47+
}
3748

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+
}
4458

4559
type composeOptions struct {
4660
filePath string
@@ -70,34 +84,6 @@ func createComposeFile(dir, composeFileContent string) (string, error) {
7084
return createFile(dir, "docmer-compose.yml", composeFileContent)
7185
}
7286

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-
10187
func containerExists(containerName string) bool {
10288
cmd := exec.Command("docker", "ps", "-a", "-f", fmt.Sprintf("name=%s", containerName))
10389

0 commit comments

Comments
 (0)