-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmain_test.go
51 lines (41 loc) · 1.04 KB
/
main_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
45
46
47
48
49
50
51
package main
import (
"testing"
"time"
)
func TestUpdateTimeDisplayNonzero(t *testing.T) {
r, err := NewExampleRouter()
if err != nil {
t.Fatalf("error making new router: %v", err)
}
r.updateDuration = time.Second
actual := r.updateTimeDisplay()
expected := "1s"
if expected != actual {
t.Fatalf("expected update duration %s but got %s", expected, actual)
}
}
func TestUpdateTimeNonzero(t *testing.T) {
r, err := NewExampleRouter()
if err != nil {
t.Fatalf("error making new router: %v", err)
}
r.updateDuration = 0
actual := r.updateTimeDisplay()
expected := "N/A"
if expected != actual {
t.Fatalf("expected update duration %s but got %s", expected, actual)
}
}
func TestUpdateTimeTruncate(t *testing.T) {
r, err := NewExampleRouter()
if err != nil {
t.Fatalf("error making new router: %v", err)
}
r.updateDuration = time.Millisecond * 123
actual := r.updateTimeDisplay()
expected := "100ms" // truncate to nearest 100ms
if expected != actual {
t.Fatalf("expected update duration %s but got %s", expected, actual)
}
}