forked from seatgeek/docker-mirror
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mirror_test.go
44 lines (36 loc) · 1.05 KB
/
mirror_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"strconv"
"testing"
"time"
)
func TestGetSleepTime(t *testing.T) {
fakeNow := time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)
// Zero
result := getSleepTime(getTimeAsString(time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)), fakeNow)
expected := 0 * time.Second
if result != expected {
t.Errorf("Expected %s got %s", expected, result)
}
// Default
result = getSleepTime(getTimeAsString(time.Date(2021, 1, 1, 0, 0, 10, 0, time.UTC)), fakeNow)
expected = 10 * time.Second
if result != expected {
t.Errorf("Expected %s got %s", expected, result)
}
// Random junk
result = getSleepTime("random-string-of-rubbish", fakeNow)
expected = 60 * time.Second
if result != expected {
t.Errorf("Expected %s got %s", expected, result)
}
// Negative
result = getSleepTime(getTimeAsString(time.Date(2020, 12, 30, 0, 0, 10, 0, time.UTC)), fakeNow)
expected = 0 * time.Second
if result != expected {
t.Errorf("Expected %s got %s", expected, result)
}
}
func getTimeAsString(date time.Time) string {
return strconv.FormatInt(date.Unix(), 10)
}