Skip to content

Commit

Permalink
boottime - add assertion on returned time
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewkroh committed Apr 10, 2024
1 parent dcb12a4 commit e667e89
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion providers/freebsd/boottime_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ func BootTime() (time.Time, error) {
return time.Time{}, fmt.Errorf("failed to get host uptime: %w", err)
}

bootTime := time.Unix(int64(tv.Sec), int64(tv.Usec)*int64(time.Microsecond))
bootTime := time.Unix(tv.Sec, tv.Usec*int64(time.Microsecond))
return bootTime, nil
}
12 changes: 6 additions & 6 deletions providers/freebsd/boottime_freebsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@
// specific language governing permissions and limitations
// under the License.

//go:build freebsd && cgo
//go:build freebsd

package freebsd

import (
"testing"
"time"

"github.com/elastic/go-sysinfo/internal/registry"
"github.com/stretchr/testify/assert"
)

var _ registry.HostProvider = freebsdSystem{}

func TestBootTime(t *testing.T) {
boottime, err := BootTime()
bootTime, err := BootTime()
if err != nil {
t.Fatal(err)
}

t.Log(boottime)
// Apply a sanity check. This assumes the host has rebooted in the last year.
assert.WithinDuration(t, time.Now().UTC(), bootTime, 365*24*time.Hour)
}
1 change: 1 addition & 0 deletions providers/freebsd/host_freebsd_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/elastic/go-sysinfo/types"
)


func init() {
registry.Register(newFreeBSDSystem(""))
}
Expand Down

0 comments on commit e667e89

Please sign in to comment.