From a22c10cd6720f2d2a5e2e08f82145d63dbbf7ade Mon Sep 17 00:00:00 2001 From: redanthrax Date: Tue, 28 Jun 2022 14:52:31 -0700 Subject: [PATCH] setup mac tests --- agent/install_darwin.go | 4 +-- agent/{install_unix.go => install_linux.go} | 4 +-- agent/system/system_darwin_test.go | 27 +++++++++++++++++++++ agent/system/system_linux_test.go | 27 +++++++++++++++++++++ agent/system/system_unix_test.go | 23 +++--------------- agent/umi/umi_unix_test.go | 9 +------ 6 files changed, 62 insertions(+), 32 deletions(-) rename agent/{install_unix.go => install_linux.go} (99%) create mode 100644 agent/system/system_darwin_test.go create mode 100644 agent/system/system_linux_test.go diff --git a/agent/install_darwin.go b/agent/install_darwin.go index 740b25a..cb3fb7c 100644 --- a/agent/install_darwin.go +++ b/agent/install_darwin.go @@ -1,5 +1,5 @@ -//go:build !windows -// +build !windows +//go:build darwin +// +build darwin package agent diff --git a/agent/install_unix.go b/agent/install_linux.go similarity index 99% rename from agent/install_unix.go rename to agent/install_linux.go index 052d141..eab8ace 100644 --- a/agent/install_unix.go +++ b/agent/install_linux.go @@ -1,5 +1,5 @@ -//go:build !windows -// +build !windows +//go:build linux +// +build linux /* Copyright 2022 AmidaWare LLC. diff --git a/agent/system/system_darwin_test.go b/agent/system/system_darwin_test.go new file mode 100644 index 0000000..4e7c126 --- /dev/null +++ b/agent/system/system_darwin_test.go @@ -0,0 +1,27 @@ +//go:build darwin +// +build darwin + +package system_test + +import ( + "testing" + + "github.com/amidaware/rmmagent/agent/system" +) + +func TestRunScript(t *testing.T) { + stdout, stderr, exitcode, err := system.RunScript("#!/bin/sh\nuname -av", "/bin/bash", nil, 30) + if err != nil { + t.Fatal(err) + } + + if stderr != "" { + t.Fatal(stderr) + } + + if exitcode != 0 { + t.Fatalf("Error: Exit Code %d", exitcode) + } + + t.Logf("Result: %s", stdout) +} diff --git a/agent/system/system_linux_test.go b/agent/system/system_linux_test.go new file mode 100644 index 0000000..5f271b4 --- /dev/null +++ b/agent/system/system_linux_test.go @@ -0,0 +1,27 @@ +//go:build linux +// +build linux + +package system_test + +import ( + "testing" + + "github.com/amidaware/rmmagent/agent/system" +) + +func TestRunScript(t *testing.T) { + stdout, stderr, exitcode, err := system.RunScript("#!/bin/sh\ncat /etc/os-release", "/bin/sh", nil, 30) + if err != nil { + t.Fatal(err) + } + + if stderr != "" { + t.Fatal(stderr) + } + + if exitcode != 0 { + t.Fatalf("Error: Exit Code %d", exitcode) + } + + t.Logf("Result: %s", stdout) +} diff --git a/agent/system/system_unix_test.go b/agent/system/system_unix_test.go index 0e96d77..d9fa548 100644 --- a/agent/system/system_unix_test.go +++ b/agent/system/system_unix_test.go @@ -1,5 +1,5 @@ -//go:build !windows -// +build !windows +//go:build darwin +// +build darwin package system_test @@ -29,7 +29,7 @@ func TestSystemRebootRequired(t *testing.T) { func TestShowStatus(t *testing.T) { output := utils.CaptureOutput(func() { system.ShowStatus("1.0.0") - }); + }) if output != "1.0.0\n" { t.Fatalf("Expected 1.0.0, got %s", output) @@ -52,21 +52,4 @@ func TestOsString(t *testing.T) { } t.Logf("OS String: %s", osString) -} - -func TestRunScript(t *testing.T) { - stdout, stderr, exitcode, err := system.RunScript("#!/bin/sh\ncat /etc/os-release", "/bin/sh", nil, 30) - if err != nil { - t.Fatal(err) - } - - if stderr != "" { - t.Fatal(stderr) - } - - if exitcode != 0 { - t.Fatalf("Error: Exit Code %d", exitcode) - } - - t.Logf("Result: %s", stdout) } \ No newline at end of file diff --git a/agent/umi/umi_unix_test.go b/agent/umi/umi_unix_test.go index c40a85e..4c21714 100644 --- a/agent/umi/umi_unix_test.go +++ b/agent/umi/umi_unix_test.go @@ -4,7 +4,6 @@ package umi_test import ( - "reflect" "testing" "github.com/amidaware/rmmagent/agent/umi" @@ -15,27 +14,21 @@ func TestGetInfo(t *testing.T) { name string expected map[string]interface{} atLeast int - expectedErrors []error }{ { name: "Get info", expected: make(map[string]interface{}), atLeast: 1, - expectedErrors: []error{}, }, } for _, tt := range testTable { t.Run(tt.name, func(t *testing.T) { - result, errs := umi.GetInfo() + result, _ := umi.GetInfo() t.Logf("result: (%v)", result) if len(result) < tt.atLeast { t.Errorf("expected at least %d, got %d", tt.atLeast, len(result)) } - - if !reflect.DeepEqual(tt.expectedErrors, errs) { - t.Errorf("expected (%v), got (%v)", tt.expectedErrors, errs) - } }) } }