removed some unix tests

This commit is contained in:
redanthrax 2022-06-28 14:34:32 -07:00
parent e926980ae5
commit f20f589fbf
8 changed files with 173 additions and 187 deletions

View file

@ -23,14 +23,6 @@ func TestGetDisks(t *testing.T) {
t.Logf("Result: %v", disks) t.Logf("Result: %v", disks)
} }
func TestAgentId(t *testing.T) {
if a.AgentID == "" {
t.Error("AgentID not set")
} else {
t.Logf("AgentID: %s", a.AgentID)
}
}
func TestSystemRebootRequired(t *testing.T) { func TestSystemRebootRequired(t *testing.T) {
result, err := a.SystemRebootRequired() result, err := a.SystemRebootRequired()
if err != nil { if err != nil {

View file

@ -1,62 +1,62 @@
package agent package agent
import ( //import (
"github.com/sirupsen/logrus" //"github.com/sirupsen/logrus"
"github.com/spf13/viper" //"github.com/spf13/viper"
"testing" //"testing"
) //)
func TestInstall(t *testing.T) { //func TestInstall(t *testing.T) {
testTable := []struct { //testTable := []struct {
name string //name string
expectedError error //expectedError error
version string //version string
log logrus.Logger //log logrus.Logger
}{ //}{
//{ //{
//name: "Install", //name: "Install",
//expectedError: nil, //expectedError: nil,
//version: "2.0.4", //version: "2.0.4",
//log: *logrus.New(), //log: *logrus.New(),
//}, //},
{ //{
name: "Install Error", //name: "Install Error",
expectedError: nil, //expectedError: nil,
version: "bad ver", //version: "bad ver",
log: *logrus.New(), //log: *logrus.New(),
}, //},
} //}
for _, tt := range testTable { //for _, tt := range testTable {
t.Run(tt.name, func(t *testing.T) { //t.Run(tt.name, func(t *testing.T) {
a := New(&tt.log, tt.version) //a := New(&tt.log, tt.version)
viper.SetConfigName("testargs.json") //viper.SetConfigName("testargs.json")
viper.SetConfigType("json") //viper.SetConfigType("json")
viper.AddConfigPath(".") //viper.AddConfigPath(".")
viper.ReadInConfig() //viper.ReadInConfig()
installer := Installer{ //installer := Installer{
RMM: viper.GetString("api"), //RMM: viper.GetString("api"),
ClientID: viper.GetInt("clientid"), //ClientID: viper.GetInt("clientid"),
SiteID: viper.GetInt("siteid"), //SiteID: viper.GetInt("siteid"),
Description: viper.GetString("description"), //Description: viper.GetString("description"),
AgentType: viper.GetString("agenttype"), //AgentType: viper.GetString("agenttype"),
Power: viper.GetBool("power"), //Power: viper.GetBool("power"),
RDP: viper.GetBool("rdp"), //RDP: viper.GetBool("rdp"),
Ping: viper.GetBool("ping"), //Ping: viper.GetBool("ping"),
Token: viper.GetString("token"), //Token: viper.GetString("token"),
LocalMesh: viper.GetString("localmesh"), //LocalMesh: viper.GetString("localmesh"),
Cert: viper.GetString("cert"), //Cert: viper.GetString("cert"),
Proxy: viper.GetString("proxy"), //Proxy: viper.GetString("proxy"),
Timeout: viper.GetDuration("timeout"), //Timeout: viper.GetDuration("timeout"),
Silent: viper.GetBool("silent"), //Silent: viper.GetBool("silent"),
NoMesh: viper.GetBool("nomesh"), //NoMesh: viper.GetBool("nomesh"),
MeshDir: viper.GetString("meshdir"), //MeshDir: viper.GetString("meshdir"),
MeshNodeID: viper.GetString("meshnodeid"), //MeshNodeID: viper.GetString("meshnodeid"),
} //}
a.Install(&installer) //a.Install(&installer)
}) //})
} //}
} //}

View file

@ -39,12 +39,10 @@ func TestGetUpdates(t *testing.T) {
testTable := []struct { testTable := []struct {
name string name string
expectedError error expectedError error
atLeast int
}{ }{
{ {
name: "Get Updates", name: "Get Updates",
expectedError: nil, expectedError: nil,
atLeast: 1,
}, },
} }
@ -55,10 +53,6 @@ func TestGetUpdates(t *testing.T) {
if !errors.Is(tt.expectedError, err) { if !errors.Is(tt.expectedError, err) {
t.Errorf("expected (%v), got (%v)", tt.expectedError, err) t.Errorf("expected (%v), got (%v)", tt.expectedError, err)
} }
if len(result) < tt.atLeast {
t.Errorf("expected at least %d, got %d", tt.atLeast, len(result))
}
}) })
} }
} }

View file

@ -1,42 +1,42 @@
package checks_test package checks_test
import ( //import (
"errors" //"errors"
"testing" //"testing"
"github.com/amidaware/rmmagent/agent/tactical/checks" //"github.com/amidaware/rmmagent/agent/tactical/checks"
"github.com/amidaware/rmmagent/agent/tactical/config" //"github.com/amidaware/rmmagent/agent/tactical/config"
) //)
func TestGetCheckInterval(t *testing.T) { //func TestGetCheckInterval(t *testing.T) {
config := config.NewAgentConfig() //config := config.NewAgentConfig()
testTable := []struct { //testTable := []struct {
name string //name string
interval int //interval int
expectedError error //expectedError error
}{ //}{
{ //{
name: "Get Check Interval", //name: "Get Check Interval",
interval: 1, //interval: 1,
expectedError: nil, //expectedError: nil,
}, //},
} //}
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, err := checks.GetCheckInterval(config.AgentID) //result, err := checks.GetCheckInterval(config.AgentID)
if result < tt.interval { //if result < tt.interval {
t.Errorf("expected greater interval than %d, got %d", tt.interval, result) //t.Errorf("expected greater interval than %d, got %d", tt.interval, result)
} //}
if !errors.Is(tt.expectedError, err) { //if !errors.Is(tt.expectedError, err) {
t.Errorf("expected (%v), got (%v)", tt.expectedError, err) //t.Errorf("expected (%v), got (%v)", tt.expectedError, err)
} //}
}) //})
} //}
} //}
//this test runs forever ////this test runs forever
//func TestCheckRunner(t *testing.T) { //func TestCheckRunner(t *testing.T) {
//config := config.NewAgentConfig() //config := config.NewAgentConfig()
//testTable := []struct { //testTable := []struct {
@ -59,28 +59,28 @@ func TestGetCheckInterval(t *testing.T) {
//} //}
//} //}
func TestRunChecks(t *testing.T) { //func TestRunChecks(t *testing.T) {
config := config.NewAgentConfig() //config := config.NewAgentConfig()
testTable := []struct { //testTable := []struct {
name string //name string
expectedError error //expectedError error
force bool //force bool
agentId string //agentId string
}{ //}{
{ //{
name: "Run Checks", //name: "Run Checks",
expectedError: nil, //expectedError: nil,
force: false, //force: false,
agentId: config.AgentID, //agentId: config.AgentID,
}, //},
} //}
for _, tt := range testTable { //for _, tt := range testTable {
t.Run(tt.name, func(t *testing.T){ //t.Run(tt.name, func(t *testing.T){
err := checks.RunChecks(tt.agentId, tt.force) //err := checks.RunChecks(tt.agentId, tt.force)
if !errors.Is(tt.expectedError, err) { //if !errors.Is(tt.expectedError, err) {
t.Errorf("expected (%v), got (%v)", tt.expectedError, err) //t.Errorf("expected (%v), got (%v)", tt.expectedError, err)
} //}
}) //})
} //}
} //}

View file

@ -1,18 +1,18 @@
package service_test package service_test
import ( //import (
"errors" //"errors"
"testing" //"testing"
"github.com/amidaware/rmmagent/agent/tactical/service" //"github.com/amidaware/rmmagent/agent/tactical/service"
) //)
func TestAgentSvc(t *testing.T) { //func TestAgentSvc(t *testing.T) {
testTable := []struct { //testTable := []struct {
name string //name string
expectedError error //expectedError error
version string //version string
}{ //}{
//{ //{
//name: "Agent Svc", //name: "Agent Svc",
//expectedError: nil, //expectedError: nil,
@ -23,14 +23,14 @@ func TestAgentSvc(t *testing.T) {
//expectedError: nil, //expectedError: nil,
//version: "bad version", //version: "bad version",
//}, //},
} //}
for _, tt := range testTable { //for _, tt := range testTable {
t.Run(tt.name, func(t *testing.T) { //t.Run(tt.name, func(t *testing.T) {
err := service.AgentSvc(tt.version) //err := service.AgentSvc(tt.version)
if errors.Is(tt.expectedError, err) { //if errors.Is(tt.expectedError, err) {
t.Errorf("expected (%v), got (%v)", tt.expectedError, err) //t.Errorf("expected (%v), got (%v)", tt.expectedError, err)
} //}
}) //})
} //}
} //}

View file

@ -1,16 +1,16 @@
package shared_test package shared_test
import ( //import (
"testing" //"testing"
"github.com/amidaware/rmmagent/agent/tactical/shared" //"github.com/amidaware/rmmagent/agent/tactical/shared"
) //)
func TestGetPythonBin(t *testing.T) { //func TestGetPythonBin(t *testing.T) {
pybin := shared.GetPythonBin() //pybin := shared.GetPythonBin()
if pybin == "" { //if pybin == "" {
t.Errorf("expected path, got %s", pybin) //t.Errorf("expected path, got %s", pybin)
} //}
t.Logf("result: %s", pybin) //t.Logf("result: %s", pybin)
} //}

View file

@ -1,16 +1,16 @@
package tactical_test package tactical_test
import ( //import (
"testing" //"testing"
"github.com/amidaware/rmmagent/agent/tactical" //"github.com/amidaware/rmmagent/agent/tactical"
) //)
func TestGetVersion(t *testing.T) { //func TestGetVersion(t *testing.T) {
version := tactical.GetVersion() //version := tactical.GetVersion()
if version == "" { //if version == "" {
t.Errorf("expected version, got empty version") //t.Errorf("expected version, got empty version")
} //}
t.Logf("got version %s", version) //t.Logf("got version %s", version)
} //}

View file

@ -3,20 +3,20 @@
package tactical_test package tactical_test
import ( //import (
"testing" //"testing"
"github.com/amidaware/rmmagent/agent/tactical" //"github.com/amidaware/rmmagent/agent/tactical"
) //)
func TestNewAgentConfig(t *testing.T) { //func TestNewAgentConfig(t *testing.T) {
config := tactical.NewAgentConfig() //config := tactical.NewAgentConfig()
if config.BaseURL == "" { //if config.BaseURL == "" {
t.Fatal("Could not get config") //t.Fatal("Could not get config")
} //}
t.Logf("Config BaseURL: %s", config.BaseURL) //t.Logf("Config BaseURL: %s", config.BaseURL)
} //}
//func TestAgentUpdate(t *testing.T) { //func TestAgentUpdate(t *testing.T) {
//url := "https://github.com/redanthrax/rmmagent/releases/download/v2.0.4/linuxagent" //url := "https://github.com/redanthrax/rmmagent/releases/download/v2.0.4/linuxagent"
@ -28,20 +28,20 @@ func TestNewAgentConfig(t *testing.T) {
//t.Log("Agent update resulted in true") //t.Log("Agent update resulted in true")
//} //}
func TestAgentUninstall(t *testing.T) { //func TestAgentUninstall(t *testing.T) {
result := tactical.AgentUninstall("foo") //result := tactical.AgentUninstall("foo")
if !result { //if !result {
t.Fatal("Agent uninstall resulted in error") //t.Fatal("Agent uninstall resulted in error")
} //}
t.Log("Agent uninstall was true") //t.Log("Agent uninstall was true")
} //}
func TestNixMeshNodeID(t *testing.T) { //func TestNixMeshNodeID(t *testing.T) {
nodeid := tactical.NixMeshNodeID() //nodeid := tactical.NixMeshNodeID()
if nodeid == "" { //if nodeid == "" {
t.Fatal("Unable to get mesh node id") //t.Fatal("Unable to get mesh node id")
} //}
t.Logf("MeshNodeID: %s", nodeid) //t.Logf("MeshNodeID: %s", nodeid)
} //}