From 72fe309a25a6f32d23e07e9c9166a39436fbe4d5 Mon Sep 17 00:00:00 2001 From: KeeganForelight Date: Tue, 20 Jun 2023 13:14:22 -0400 Subject: [PATCH] added barebones tests for system package --- internal/pkg/system/hwinfo_test.go | 35 +++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/internal/pkg/system/hwinfo_test.go b/internal/pkg/system/hwinfo_test.go index 968e01a..c06a6ca 100644 --- a/internal/pkg/system/hwinfo_test.go +++ b/internal/pkg/system/hwinfo_test.go @@ -4,9 +4,38 @@ import ( "testing" ) +// TestGetInfo ensures that the array can be populated with device info. func TestGetInfo(t *testing.T) { - info, err := GetInfo() - if err != nil { - panic(err) + if err := getInfo(); err != nil { + t.Fatalf(`getInfo() failed %v`, err) } } + +// TestGetIP tests that the IP is returned without error and not empty. +func TestGetIP(t *testing.T) { + if ip, err := GetIP(); err != nil || ip == "" { + t.Fatalf(`GetIP() failed, got %s, err: %v`, ip, err) + } +} + +// TestGetID tests that the ID is returned without error and not empty. +func TestGetID(t *testing.T) { + if id, err := GetID(); err != nil || id == 0 { + t.Fatalf(`GetID() failed, got %d %v`, id, err) + } +} + +// TestGetModel tests that the Model is returned without error and not empty. +func TestGetModel(t *testing.T) { + if model, err := GetModel(); err != nil || model == "" { + t.Fatalf(`GetModel() failed, got %s %v`, model, err) + } +} + +// TestGetModel tests that the correct error is thrown as the bus does not exist on the test rig. +func TestGetBus(t *testing.T) { + if bus, err := GetBus(); err != ErrBusNotFound { + t.Fatalf(`GetBus() should fail, got %d %v`, bus, err) + } + +}