-
Notifications
You must be signed in to change notification settings - Fork 3
/
main_test.go
53 lines (50 loc) · 1.15 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
52
53
package main
import (
"testing"
"time"
)
func Test_device_isActive(t *testing.T) {
type fields struct {
timeSinceLastSeen time.Duration
}
tests := []struct {
name string
timeSinceLastSeen time.Duration
want bool
}{
{name: "active", timeSinceLastSeen: time.Duration(0), want: true},
{name: "inactive", timeSinceLastSeen: time.Duration(10), want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
d := &device{
timeSinceLastSeen: tt.timeSinceLastSeen,
}
if got := d.isActive(); got != tt.want {
t.Errorf("device.isActive() = %v, want %v", got, tt.want)
}
})
}
}
func Test_truncateString(t *testing.T) {
type args struct {
str string
num int
}
tests := []struct {
name string
args args
want string
}{
{"too short for concatenation", args{"s", 10}, "s"},
{"example 1", args{"hello", 2}, "he..."},
{"example 1", args{"hello there", 8}, "hello..."},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := truncateString(tt.args.str, tt.args.num); got != tt.want {
t.Errorf("truncateString() = %v, want %v", got, tt.want)
}
})
}
}