Skip to content

Commit 3a8a565

Browse files
committed
tests: add tests for config.go
1 parent f46d486 commit 3a8a565

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

config_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package dockergen
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestParseWait(t *testing.T) {
10+
incorrectIntervals := []string{
11+
"500x", // Incorrect min interval
12+
"500s:4x", // Incorrect max interval
13+
"1m:1s", // Min interval larger than max interval
14+
}
15+
16+
for _, intervalString := range incorrectIntervals {
17+
wait, err := ParseWait(intervalString)
18+
assert.Error(t, err)
19+
assert.Nil(t, wait)
20+
}
21+
22+
correctIntervals := map[string]Wait{
23+
"": {0, 0}, // Empty time interval string
24+
"1ms": {1000000, 4000000}, // Correct min interval without max
25+
"1ms:111ms": {1000000, 111000000}, // Correct min:max time interval
26+
}
27+
28+
for intervalString, expectedWait := range correctIntervals {
29+
wait, err := ParseWait(intervalString)
30+
assert.NoError(t, err)
31+
assert.Equal(t, &expectedWait, wait)
32+
}
33+
}
34+
35+
func TestWaitUnmarshalText(t *testing.T) {
36+
// Correct min:max time interval
37+
intervalBytes := []byte("1ms:2ms")
38+
expectedWait := &Wait{1000000, 2000000}
39+
wait := new(Wait)
40+
err := wait.UnmarshalText(intervalBytes)
41+
assert.NoError(t, err)
42+
assert.Equal(t, expectedWait, wait)
43+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/opencontainers/runc v0.1.1 // indirect
2222
github.com/opencontainers/selinux v1.8.0 // indirect
2323
github.com/sirupsen/logrus v1.8.1 // indirect
24-
github.com/stretchr/testify v1.7.0 // indirect
24+
github.com/stretchr/testify v1.7.0
2525
golang.org/x/sys v0.0.0-20210331175145-43e1dd70ce54 // indirect
2626
gotest.tools v2.2.0+incompatible // indirect
2727
)

0 commit comments

Comments
 (0)