testing for install - in progress
This commit is contained in:
parent
6457ad290f
commit
7457bf0b93
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@ -10,7 +10,7 @@
|
||||
"request": "launch",
|
||||
"mode": "debug",
|
||||
"env": {},
|
||||
"args": ["-m", "svc", "-logto", "stdout"],
|
||||
"args": ["-m", "svc", "-log", "DEBUG", "-logto", "stdout"],
|
||||
"buildFlags": "-tags=DEBUG",
|
||||
"program": "${workspaceRoot}"
|
||||
}
|
||||
|
@ -6,4 +6,9 @@ https://github.com/amidaware/tacticalrmm
|
||||
env CGO_ENABLED=0 GOOS=<GOOS> GOARCH=<GOARCH> go build -ldflags "-s -w"
|
||||
```
|
||||
|
||||
### tests
|
||||
Navigate to agent directory
|
||||
|
||||
```
|
||||
go test -vet=off
|
||||
```
|
@ -132,6 +132,10 @@ func NewAgentConfig() *rmm.AgentConfig {
|
||||
viper.SetConfigType("json")
|
||||
viper.AddConfigPath("/etc/")
|
||||
viper.AddConfigPath(".")
|
||||
if strings.HasSuffix(os.Args[0], ".test") {
|
||||
viper.AddConfigPath("../")
|
||||
}
|
||||
|
||||
err := viper.ReadInConfig()
|
||||
|
||||
if err != nil {
|
||||
|
35
agent/agent_test.go
Normal file
35
agent/agent_test.go
Normal 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
49
agent/install_test.go
Normal 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)
|
||||
}
|
@ -50,7 +50,7 @@ var (
|
||||
|
||||
func (a *Agent) RunRPC() {
|
||||
if rmm.DEBUG {
|
||||
a.Logger.Infoln("DEBUG MODE")
|
||||
a.Logger.Infoln("DEBUG BUILD STARTED")
|
||||
}
|
||||
|
||||
a.Logger.Infoln("Agent service started")
|
||||
|
4
agent/testargs.json
Normal file
4
agent/testargs.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"api": "https://api.hothcorp.com:8000",
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user