-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoutmp_test.go
67 lines (61 loc) · 1.67 KB
/
goutmp_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2023~2024 wangqi. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package goutmp
import (
"testing"
"time"
)
func TestHasUtmpSupport(t *testing.T) {
if !HasUtmpSupport() {
t.Skip("the system doesn't support utmpx access.")
}
}
func TestUtmpxAccess(t *testing.T) {
tc := []struct {
time time.Time
label string
user string
host string
line string
id int
pid int
typ0 int
}{
{label: "normal", user: "john", host: "192.168.0.1", line: "pts/0", id: 120, pid: 512, typ0: USER_PROCESS, time: time.Now()},
}
for _, v := range tc {
t.Run(v.label, func(t *testing.T) {
u := &Utmpx{}
u.SetUser(v.user)
u.SetHost(v.host)
u.SetLine(v.line)
u.SetId(v.id)
u.SetPid(v.pid)
u.SetType(v.typ0)
u.SetTime(v.time)
if u.GetUser() != v.user {
t.Errorf("%q GetUser expect %s, got %s\n", v.label, v.user, u.GetUser())
}
if u.GetHost() != v.host {
t.Errorf("%q GetHost expect %s, got %s\n", v.label, v.host, u.GetHost())
}
if u.GetLine() != v.line {
t.Errorf("%q GetLine expect %s, got %s\n", v.label, v.line, u.GetLine())
}
if u.GetId() != v.id {
t.Errorf("%q GetId expect %d, got %d\n", v.label, v.id, u.GetId())
}
if u.GetPid() != v.pid {
t.Errorf("%q GetPid expect %d, got %d\n", v.label, v.pid, u.GetPid())
}
if u.GetType() != v.typ0 {
t.Errorf("%q GetType expect %d, got %d\n", v.label, v.typ0, u.GetType())
}
if u.GetTime() != v.time {
t.Skip("please reconsider convertion between TimeVal and Time.")
// t.Errorf("%q GetTime expect \n%s, got \n%s\n", v.label, v.time, u.GetTime())
}
})
}
}