From 6853f1639eb92f7fd795d96270f36f9ddb713410 Mon Sep 17 00:00:00 2001 From: redanthrax Date: Wed, 22 Jun 2022 16:20:42 -0700 Subject: [PATCH] additional functions and testing --- agent/software/software_unix.go | 23 ++++++++++---- agent/umi/{umi_linux.go => umi_unix.go} | 0 agent/umi/umi_unix_test.go | 40 +++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 5 deletions(-) rename agent/umi/{umi_linux.go => umi_unix.go} (100%) create mode 100644 agent/umi/umi_unix_test.go diff --git a/agent/software/software_unix.go b/agent/software/software_unix.go index 13c986d..58a492e 100644 --- a/agent/software/software_unix.go +++ b/agent/software/software_unix.go @@ -3,10 +3,23 @@ package software +import ( + "strings" + + "github.com/amidaware/rmmagent/agent/system" +) + 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() {} - -func InstallWithChoco(name string) (string, error) { return "", nil } \ No newline at end of file + return software, nil +} \ No newline at end of file diff --git a/agent/umi/umi_linux.go b/agent/umi/umi_unix.go similarity index 100% rename from agent/umi/umi_linux.go rename to agent/umi/umi_unix.go diff --git a/agent/umi/umi_unix_test.go b/agent/umi/umi_unix_test.go new file mode 100644 index 0000000..3f01e16 --- /dev/null +++ b/agent/umi/umi_unix_test.go @@ -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) + } + }) + } +}