testing for install - in progress

This commit is contained in:
redanthrax 2022-06-15 16:37:35 -07:00
parent 6457ad290f
commit 7457bf0b93
7 changed files with 99 additions and 2 deletions

2
.vscode/launch.json vendored
View File

@ -10,7 +10,7 @@
"request": "launch", "request": "launch",
"mode": "debug", "mode": "debug",
"env": {}, "env": {},
"args": ["-m", "svc", "-logto", "stdout"], "args": ["-m", "svc", "-log", "DEBUG", "-logto", "stdout"],
"buildFlags": "-tags=DEBUG", "buildFlags": "-tags=DEBUG",
"program": "${workspaceRoot}" "program": "${workspaceRoot}"
} }

View File

@ -6,4 +6,9 @@ https://github.com/amidaware/tacticalrmm
env CGO_ENABLED=0 GOOS=<GOOS> GOARCH=<GOARCH> go build -ldflags "-s -w" env CGO_ENABLED=0 GOOS=<GOOS> GOARCH=<GOARCH> go build -ldflags "-s -w"
``` ```
### tests
Navigate to agent directory
```
go test -vet=off
```

View File

@ -132,6 +132,10 @@ func NewAgentConfig() *rmm.AgentConfig {
viper.SetConfigType("json") viper.SetConfigType("json")
viper.AddConfigPath("/etc/") viper.AddConfigPath("/etc/")
viper.AddConfigPath(".") viper.AddConfigPath(".")
if strings.HasSuffix(os.Args[0], ".test") {
viper.AddConfigPath("../")
}
err := viper.ReadInConfig() err := viper.ReadInConfig()
if err != nil { if err != nil {

35
agent/agent_test.go Normal file
View File

@ -0,0 +1,35 @@
package agent
import (
"bytes"
"io"
"os"
"testing"
)
func captureOutput(f func()) string {
old := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w
f()
w.Close()
os.Stdout = old
var buf bytes.Buffer
io.Copy(&buf, r)
return buf.String()
}
func TestShowStatus(t *testing.T) {
var (
version = "2.0.4"
)
output := captureOutput(func() {
ShowStatus(version)
})
if output != (version + "\n") {
t.Errorf("ShowStatus output not equal to version defined.")
}
}

49
agent/install_test.go Normal file
View File

@ -0,0 +1,49 @@
package agent
import (
"testing"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"strconv"
)
func TestInstall(t *testing.T) {
var (
version = "2.0.4"
log = logrus.New()
)
a := New(log, version)
viper.SetConfigName("testargs.json")
viper.SetConfigType("json")
viper.AddConfigPath(".")
cid, err := strconv.Atoi(viper.GetString("clientid"))
if err != nil {
cid = 0
}
installer := Installer {
RMM: viper.GetString("api"),
ClientID: cid,
SiteID: *siteID,
Description: *desc,
AgentType: *atype,
Power: *power,
RDP: *rdp,
Ping: *ping,
Token: *token,
LocalMesh: *localMesh,
Cert: *cert,
Proxy: *proxy,
Timeout: *timeout,
Silent: *silent,
NoMesh: *noMesh,
MeshDir: *meshDir,
MeshNodeID: *meshNodeID,
}
a.Install(&installer)
}

View File

@ -50,7 +50,7 @@ var (
func (a *Agent) RunRPC() { func (a *Agent) RunRPC() {
if rmm.DEBUG { if rmm.DEBUG {
a.Logger.Infoln("DEBUG MODE") a.Logger.Infoln("DEBUG BUILD STARTED")
} }
a.Logger.Infoln("Agent service started") a.Logger.Infoln("Agent service started")

4
agent/testargs.json Normal file
View File

@ -0,0 +1,4 @@
{
"api": "https://api.hothcorp.com:8000",
}