|
| 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 | +} |
0 commit comments