Skip to content

Commit 3e361ba

Browse files
committed
Refactor to avoid panic on test execution
Signed-off-by: Ulysses Souza <[email protected]>
1 parent 638b527 commit 3e361ba

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

client/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.13.3 AS dev
1+
FROM golang:1.14.0 AS dev
22
WORKDIR /
33
COPY main.go /
44
RUN go mod init github.com/compose-spec/compatibility-test-suite/client

compliance_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"time"
88

99
"gopkg.in/yaml.v2"
10-
"gotest.tools/v3/assert"
1110
)
1211

1312
const (
@@ -124,15 +123,15 @@ func TestUdpPort(t *testing.T) {
124123
udpValue := "myUdpvalue"
125124

126125
ServerAddr, err := net.ResolveUDPAddr("udp", localhost+":10001")
127-
assert.NilError(h.T, err)
126+
h.NilError(err)
128127
LocalAddr, err := net.ResolveUDPAddr("udp", localhost+":0")
129-
assert.NilError(h.T, err)
128+
h.NilError(err)
130129
Conn, err := net.DialUDP("udp", LocalAddr, ServerAddr)
131-
assert.NilError(h.T, err)
130+
h.NilError(err)
132131
defer Conn.Close()
133132
buf := []byte(fmt.Sprintf("{\"request\":%q}", udpValue))
134133
_, err = Conn.Write(buf)
135-
assert.NilError(h.T, err)
134+
h.NilError(err)
136135
time.Sleep(time.Second) // Wait for the registration
137136
actual := h.getHttpBody(udpEntrypoint)
138137
expected := jsonResponse(udpValue)
@@ -152,7 +151,7 @@ func TestScaling(t *testing.T) {
152151
actual := h.getHttpBody(scaleEntrypoint)
153152
responseArray := Response{}
154153
err := yaml.Unmarshal([]byte(actual), &responseArray)
155-
assert.NilError(h.T, err)
154+
h.NilError(err)
156155
h.Check("3", responseArray.Response)
157156
})
158157
}

server/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.13.3 AS dev
1+
FROM golang:1.14.0 AS dev
22
WORKDIR /
33
COPY main.go /
44
RUN go mod init github.com/compose-spec/compatibility-test-suite/server

tests_helper.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ func (h TestHelper) Check(expected, actual string) {
8585
assert.Check(h.T, expected == actual, h.assertSpecReferenceMessage(expected, actual))
8686
}
8787

88+
func (h TestHelper) NilError(e error) {
89+
assert.Check(h.T, e == nil, h.assertSpecReferenceMessage("", fmt.Sprintf("%q", e)))
90+
}
91+
8892
func (h TestHelper) assertSpecReferenceMessage(expected, actual string) string {
8993
return fmt.Sprintf("\n- expected: %q\n+ actual: %q\n%s", expected, actual, h.specReferenceMessage())
9094
}
@@ -102,10 +106,10 @@ func (h TestHelper) getSpecReference() string {
102106

103107
func (h TestHelper) readConfig(configPath string) (*Config, error) {
104108
b, err := ioutil.ReadFile(configPath)
105-
assert.NilError(h.T, err)
109+
h.NilError(err)
106110
c := Config{}
107111
err = yaml.Unmarshal(b, &c)
108-
assert.NilError(h.T, err)
112+
h.NilError(err)
109113
return &c, nil
110114
}
111115

@@ -145,9 +149,9 @@ func (h TestHelper) execCmd(c *Config, opts []string) {
145149

146150
func (h TestHelper) listDirs(testDir string) []string {
147151
currDir, err := os.Getwd()
148-
assert.NilError(h.T, err)
152+
h.NilError(err)
149153
files, err := ioutil.ReadDir(filepath.Join(currDir, testDir))
150-
assert.NilError(h.T, err)
154+
h.NilError(err)
151155
var dirs []string
152156
for _, f := range files {
153157
if f.IsDir() && !strings.HasPrefix(f.Name(), ".") {
@@ -159,9 +163,9 @@ func (h TestHelper) listDirs(testDir string) []string {
159163

160164
func (h TestHelper) listFiles(dir string) []string {
161165
currDir, err := os.Getwd()
162-
assert.NilError(h.T, err)
166+
h.NilError(err)
163167
content, err := ioutil.ReadDir(filepath.Join(currDir, dir))
164-
assert.NilError(h.T, err)
168+
h.NilError(err)
165169
var configFiles []string
166170
for _, f := range content {
167171
if !f.IsDir() && strings.HasSuffix(f.Name(), ".yml") {
@@ -186,10 +190,10 @@ func (h TestHelper) checkCleanUp(c *Config) {
186190

187191
func (h TestHelper) getHttpBody(address string) string {
188192
resp, err := http.Get(address)
189-
assert.NilError(h.T, err)
193+
h.NilError(err)
190194
defer resp.Body.Close()
191195
body, err := ioutil.ReadAll(resp.Body)
192-
assert.NilError(h.T, err)
196+
h.NilError(err)
193197
return string(body)
194198
}
195199

0 commit comments

Comments
 (0)