additional functions and testing

This commit is contained in:
redanthrax 2022-06-22 16:20:42 -07:00
parent f0cb4f4b3f
commit 6853f1639e
3 changed files with 58 additions and 5 deletions

View file

@ -3,10 +3,23 @@
package software package software
import (
"strings"
"github.com/amidaware/rmmagent/agent/system"
)
func GetInstalledSoftware() ([]Software, error) { func GetInstalledSoftware() ([]Software, error) {
return []Software{}, nil opts := system.NewCMDOpts()
} opts.Command = "find /usr/share/applications -maxdepth 1 -type f -exec basename {} .desktop \\; | sort"
result := system.CmdV2(opts)
softwares := strings.Split(result.Stdout, "\n")
software := []Software{}
for _, s := range softwares {
software = append(software, Software {
Name: s,
})
}
func InstallChoco() {} return software, nil
}
func InstallWithChoco(name string) (string, error) { return "", nil }

View file

@ -0,0 +1,40 @@
//go:build !windows
// +build !windows
package umi_test
import (
"reflect"
"testing"
"github.com/amidaware/rmmagent/agent/umi"
)
func TestGetInfo(t *testing.T) {
testTable := []struct {
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()
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)
}
})
}
}