1
1
package main
2
2
3
3
import (
4
+ "fmt"
4
5
"testing"
5
6
"time"
6
-
7
- "gotest.tools/v3/assert"
8
7
)
9
8
10
9
const (
@@ -17,49 +16,78 @@ const (
17
16
)
18
17
19
18
func TestSimpleLifecycle (t * testing.T ) {
20
- h := TestHelper {T : t , testDir : "simple_lifecycle" }
21
- h .TestUpDown (func (t * testing.T ) {
19
+ h := TestHelper {
20
+ T : t ,
21
+ testDir : "simple_lifecycle" ,
22
+ }
23
+ h .TestUpDown (func () {
22
24
time .Sleep (time .Second )
23
25
})
24
26
}
25
27
26
28
func TestSimpleNetwork (t * testing.T ) {
27
- h := TestHelper {T : t , testDir : "simple_network" }
28
- h .TestUpDown (func (t * testing.T ) {
29
+ h := TestHelper {
30
+ T : t ,
31
+ testDir : "simple_network" ,
32
+ specRef : "Networks-top-level-element" ,
33
+ }
34
+ h .TestUpDown (func () {
29
35
actual := h .getHttpBody (pingUrl )
30
- assert .Assert (t , actual == "{\" response\" :\" PONG FROM TARGET\" }\n " )
36
+ expected := jsonResponse ("PONG FROM TARGET" )
37
+ h .Check (expected , actual )
31
38
})
32
39
}
33
40
34
41
func TestSimpleNetworkFail (t * testing.T ) {
35
- h := TestHelper {T : t , testDir : "simple_network" }
36
- h .TestUpDown (func (t * testing.T ) {
42
+ h := TestHelper {
43
+ T : t ,
44
+ testDir : "simple_network" ,
45
+ specRef : "Networks-top-level-element" ,
46
+ }
47
+ h .TestUpDown (func () {
37
48
actual := h .getHttpBody ("http://localhost:8080/ping?address=notatarget:8080/ping" )
38
- assert .Assert (t , actual == "{\" response\" :\" Could not reach address: notatarget:8080/ping\" }\n " )
49
+ expected := jsonResponse ("Could not reach address: notatarget:8080/ping" )
50
+ h .Check (expected , actual )
39
51
})
40
52
}
41
53
42
54
func TestDifferentNetworks (t * testing.T ) {
43
- h := TestHelper {T : t , testDir : "different_networks" }
44
- h .TestUpDown (func (t * testing.T ) {
55
+ h := TestHelper {
56
+ T : t ,
57
+ testDir : "different_networks" ,
58
+ specRef : "Networks-top-level-element" ,
59
+ }
60
+ h .TestUpDown (func () {
45
61
actual := h .getHttpBody (pingUrl )
46
- assert .Assert (t , actual == "{\" response\" :\" Could not reach address: target:8080/ping\" }\n " )
62
+ expected := jsonResponse ("Could not reach address: target:8080/ping" )
63
+ h .Check (expected , actual )
47
64
})
48
65
}
49
66
50
67
func TestVolumeFile (t * testing.T ) {
51
- h := TestHelper {T : t , testDir : "simple_volume" }
52
- h .TestUpDown (func (t * testing.T ) {
68
+ h := TestHelper {
69
+ T : t ,
70
+ testDir : "simple_volume" ,
71
+ specRef : "volumes-top-level-element" ,
72
+ }
73
+ h .TestUpDown (func () {
53
74
actual := h .getHttpBody (volumeUrl + "test_volume.txt" )
54
- assert .Assert (t , actual == "{\" response\" :\" MYVOLUME\" }\n " )
75
+ expected := jsonResponse ("MYVOLUME" )
76
+ h .Check (expected , actual )
77
+
55
78
})
56
79
}
57
80
58
81
func TestSecretFile (t * testing.T ) {
59
- h := TestHelper {T : t , testDir : "simple_secretfile" }
60
- h .TestUpDown (func (t * testing.T ) {
82
+ h := TestHelper {
83
+ T : t ,
84
+ testDir : "simple_secretfile" ,
85
+ specRef : "secrets-top-level-element" ,
86
+ }
87
+ h .TestUpDown (func () {
61
88
actual := h .getHttpBody (volumeUrl + "test_secret.txt" )
62
- assert .Assert (t , actual == "{\" response\" :\" MYSECRET\" }\n " )
89
+ expected := jsonResponse ("MYSECRET" )
90
+ h .Check (expected , actual )
63
91
})
64
92
}
65
93
@@ -68,9 +96,15 @@ func TestConfigFile(t *testing.T) {
68
96
T : t ,
69
97
testDir : "simple_configfile" ,
70
98
skipCommands : []string {"docker-composeV1" },
99
+ specRef : "configs-top-level-element" ,
71
100
}
72
- h .TestUpDown (func (t * testing. T ) {
101
+ h .TestUpDown (func () {
73
102
actual := h .getHttpBody (volumeUrl + "test_config.txt" )
74
- assert .Assert (t , actual == "{\" response\" :\" MYCONFIG\" }\n " )
103
+ expected := jsonResponse ("MYCONFIG" )
104
+ h .Check (expected , actual )
75
105
})
76
106
}
107
+
108
+ func jsonResponse (content string ) string {
109
+ return fmt .Sprintf ("{\" response\" :\" %s\" }\n " , content )
110
+ }
0 commit comments