Cleanup[linux] + lint
This commit is contained in:
parent
a39de9c865
commit
e86d7171e0
2
go.mod
2
go.mod
@ -13,7 +13,7 @@ require (
|
|||||||
require (
|
require (
|
||||||
go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect
|
go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect
|
||||||
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 // indirect
|
go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 // indirect
|
||||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 // indirect
|
golang.org/x/sys v0.3.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
retract v0.0.0-20220210125455-40e3d2190a52
|
retract v0.0.0-20220210125455-40e3d2190a52
|
||||||
|
4
go.sum
4
go.sum
@ -24,8 +24,8 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
|
|||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 h1:foEbQz/B0Oz6YIqu/69kfXPYeFQAuuMYFkjaqXzl5Wo=
|
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
|
||||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
/*
|
/*
|
||||||
some interesting information on RAM, sysinfo, and /proc/meminfo
|
some interesting information on RAM, sysinfo, and /proc/meminfo
|
||||||
|
|
||||||
- https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773
|
- https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773 //nolint:lll
|
||||||
- https://github.com/mmalecki/procps/blob/master/proc/sysinfo.c
|
- https://github.com/mmalecki/procps/blob/master/proc/sysinfo.c
|
||||||
|
|
||||||
in the second link we see that even procps is parsing /proc/meminfo to get the RAM information
|
in the second link we see that even procps is parsing /proc/meminfo to get the RAM information
|
||||||
|
@ -13,31 +13,35 @@ import (
|
|||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUptime(t *testing.T) {
|
// getUptimeControlValue from /proc/uptime to compare against our syscall value.
|
||||||
|
func getUptimeControlValue(t *testing.T) time.Duration {
|
||||||
f, err := os.Open("/proc/uptime")
|
f, err := os.Open("/proc/uptime")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to open /proc/uptime with error: %v", err)
|
t.Fatalf("failed to open /proc/uptime with error: %v", err)
|
||||||
}
|
}
|
||||||
buf, err := io.ReadAll(f)
|
buf, err := io.ReadAll(f)
|
||||||
|
|
||||||
// calling Uptime() here to try and get the same time as the file
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to read /proc/uptime with error: %v", err)
|
t.Fatalf("failed to read /proc/uptime with error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Logf("read %d bytes from /proc/uptime: %s", len(buf), buf)
|
t.Logf("read %d bytes from /proc/uptime: %s", len(buf), buf)
|
||||||
|
|
||||||
controlSeconds, err := strconv.ParseInt(string(buf[:strings.IndexByte(string(buf), '.')]), 10, 64)
|
controlSeconds, err := strconv.ParseInt(string(buf[:strings.IndexByte(string(buf), '.')]), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to parse /proc/uptime with error: %e", err)
|
t.Fatalf("failed to parse /proc/uptime with error: %e", err)
|
||||||
}
|
}
|
||||||
if controlSeconds < 1 {
|
|
||||||
t.Fatalf("failed to parse /proc/uptime")
|
|
||||||
}
|
|
||||||
uptimeCtrl := time.Duration(controlSeconds) * time.Second
|
|
||||||
t.Logf("control uptime: %v", uptimeCtrl)
|
|
||||||
|
|
||||||
// ---
|
if controlSeconds < 1 {
|
||||||
|
t.Fatalf("failed to parse /proc/uptime (zero value)")
|
||||||
|
}
|
||||||
|
|
||||||
|
return time.Duration(controlSeconds) * time.Second
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUptime(t *testing.T) {
|
||||||
|
uptimeCtrl := getUptimeControlValue(t)
|
||||||
|
t.Logf("control uptime: %v", uptimeCtrl)
|
||||||
|
|
||||||
uptime, err := Uptime()
|
uptime, err := Uptime()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -69,12 +73,12 @@ func TestUptime(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !matching {
|
if !matching {
|
||||||
t.Fatalf("uptime does not match control uptime: %v != %v", uptime, uptimeCtrl)
|
t.Errorf("uptime does not match control uptime: %v != %v", uptime, uptimeCtrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSysinfo(t *testing.T) {
|
func TestSysinfo(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
si, err := Sysinfo()
|
si, err := Sysinfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to get sysinfo with error: %e", err)
|
t.Fatalf("failed to get sysinfo with error: %e", err)
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
ipa "inet.af/netaddr"
|
ipa "inet.af/netaddr"
|
||||||
)
|
)
|
||||||
|
|
||||||
var testdata29 string = `
|
var testdata29 = `
|
||||||
192.168.69.240
|
192.168.69.240
|
||||||
192.168.69.241
|
192.168.69.241
|
||||||
192.168.69.242
|
192.168.69.242
|
||||||
@ -75,7 +75,7 @@ func TestIterateNetRange(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "evenboguser",
|
name: "evenboguser",
|
||||||
args: args{ips: int(5)},
|
args: args{ips: 5},
|
||||||
want: nil,
|
want: nil,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user