setup mac tests

This commit is contained in:
redanthrax 2022-06-28 14:52:31 -07:00
parent f20f589fbf
commit a22c10cd67
6 changed files with 62 additions and 32 deletions

View file

@ -1,5 +1,5 @@
//go:build !windows //go:build darwin
// +build !windows // +build darwin
package agent package agent

View file

@ -1,5 +1,5 @@
//go:build !windows //go:build linux
// +build !windows // +build linux
/* /*
Copyright 2022 AmidaWare LLC. Copyright 2022 AmidaWare LLC.

View file

@ -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)
}

View file

@ -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)
}

View file

@ -1,5 +1,5 @@
//go:build !windows //go:build darwin
// +build !windows // +build darwin
package system_test package system_test
@ -29,7 +29,7 @@ func TestSystemRebootRequired(t *testing.T) {
func TestShowStatus(t *testing.T) { func TestShowStatus(t *testing.T) {
output := utils.CaptureOutput(func() { output := utils.CaptureOutput(func() {
system.ShowStatus("1.0.0") system.ShowStatus("1.0.0")
}); })
if output != "1.0.0\n" { if output != "1.0.0\n" {
t.Fatalf("Expected 1.0.0, got %s", output) t.Fatalf("Expected 1.0.0, got %s", output)
@ -52,21 +52,4 @@ func TestOsString(t *testing.T) {
} }
t.Logf("OS String: %s", osString) 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)
} }

View file

@ -4,7 +4,6 @@
package umi_test package umi_test
import ( import (
"reflect"
"testing" "testing"
"github.com/amidaware/rmmagent/agent/umi" "github.com/amidaware/rmmagent/agent/umi"
@ -15,27 +14,21 @@ func TestGetInfo(t *testing.T) {
name string name string
expected map[string]interface{} expected map[string]interface{}
atLeast int atLeast int
expectedErrors []error
}{ }{
{ {
name: "Get info", name: "Get info",
expected: make(map[string]interface{}), expected: make(map[string]interface{}),
atLeast: 1, atLeast: 1,
expectedErrors: []error{},
}, },
} }
for _, tt := range testTable { for _, tt := range testTable {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
result, errs := umi.GetInfo() result, _ := umi.GetInfo()
t.Logf("result: (%v)", result) t.Logf("result: (%v)", result)
if len(result) < tt.atLeast { if len(result) < tt.atLeast {
t.Errorf("expected at least %d, got %d", tt.atLeast, len(result)) 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)
}
}) })
} }
} }