more tests
This commit is contained in:
parent
2e095270f5
commit
234f524a0e
7 changed files with 161 additions and 4 deletions
|
|
@ -36,6 +36,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func PostPayload(payload interface{}, url string) error {
|
func PostPayload(payload interface{}, url string) error {
|
||||||
|
fmt.Println(restyC.BaseURL)
|
||||||
_, err := restyC.R().SetBody(payload).Post(url)
|
_, err := restyC.R().SetBody(payload).Post(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
85
agent/tactical/checks/checks_test.go
Normal file
85
agent/tactical/checks/checks_test.go
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
package checks_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/amidaware/rmmagent/agent/tactical/checks"
|
||||||
|
"github.com/amidaware/rmmagent/agent/tactical/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetCheckInterval(t *testing.T) {
|
||||||
|
config := config.NewAgentConfig()
|
||||||
|
testTable := []struct {
|
||||||
|
name string
|
||||||
|
interval int
|
||||||
|
expectedError error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Get Check Interval",
|
||||||
|
interval: 1,
|
||||||
|
expectedError: nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range testTable {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
result, err := checks.GetCheckInterval(config.AgentID)
|
||||||
|
if result < tt.interval {
|
||||||
|
t.Errorf("expected greater interval than %d, got %d", tt.interval, result)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !errors.Is(tt.expectedError, err) {
|
||||||
|
t.Errorf("expected (%v), got (%v)", tt.expectedError, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCheckRunner(t *testing.T) {
|
||||||
|
config := config.NewAgentConfig()
|
||||||
|
testTable := []struct {
|
||||||
|
name string
|
||||||
|
expectedError error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Check Runner",
|
||||||
|
expectedError: nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range testTable {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
err := checks.CheckRunner(config.AgentID)
|
||||||
|
if !errors.Is(tt.expectedError, err) {
|
||||||
|
t.Errorf("expected (%v), got (%v)", tt.expectedError, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRunChecks(t *testing.T) {
|
||||||
|
config := config.NewAgentConfig()
|
||||||
|
testTable := []struct {
|
||||||
|
name string
|
||||||
|
expectedError error
|
||||||
|
force bool
|
||||||
|
agentId string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Run Checks",
|
||||||
|
expectedError: nil,
|
||||||
|
force: false,
|
||||||
|
agentId: config.AgentID,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range testTable {
|
||||||
|
t.Run(tt.name, func(t *testing.T){
|
||||||
|
err := checks.RunChecks(tt.agentId, tt.force)
|
||||||
|
if !errors.Is(tt.expectedError, err) {
|
||||||
|
t.Errorf("expected (%v), got (%v)", tt.expectedError, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,6 +14,7 @@ func NewAgentConfig() *AgentConfig {
|
||||||
viper.SetConfigType("json")
|
viper.SetConfigType("json")
|
||||||
viper.AddConfigPath("/etc/")
|
viper.AddConfigPath("/etc/")
|
||||||
viper.AddConfigPath(".")
|
viper.AddConfigPath(".")
|
||||||
|
viper.AddConfigPath("../.")
|
||||||
err := viper.ReadInConfig()
|
err := viper.ReadInConfig()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ var (
|
||||||
installWinUpdateLocker uint32
|
installWinUpdateLocker uint32
|
||||||
)
|
)
|
||||||
|
|
||||||
func RunRPC(version string) {
|
func RunRPC(version string) error {
|
||||||
config := config.NewAgentConfig()
|
config := config.NewAgentConfig()
|
||||||
go service.RunAsService(version)
|
go service.RunAsService(version)
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
@ -45,6 +45,7 @@ func RunRPC(version string) {
|
||||||
server := fmt.Sprintf("tls://%s:4222", config.APIURL)
|
server := fmt.Sprintf("tls://%s:4222", config.APIURL)
|
||||||
nc, err := nats.Connect(server, opts...)
|
nc, err := nats.Connect(server, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
nc.Subscribe(config.AgentID, func(msg *nats.Msg) {
|
nc.Subscribe(config.AgentID, func(msg *nats.Msg) {
|
||||||
|
|
@ -457,11 +458,12 @@ func RunRPC(version string) {
|
||||||
nc.Flush()
|
nc.Flush()
|
||||||
|
|
||||||
if err := nc.LastError(); err != nil {
|
if err := nc.LastError(); err != nil {
|
||||||
//a.Logger.Errorln(err)
|
return err
|
||||||
os.Exit(1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Start(version string, _ ksvc.Service) error {
|
func Start(version string, _ ksvc.Service) error {
|
||||||
|
|
|
||||||
31
agent/tactical/rpc/rpc_test.go
Normal file
31
agent/tactical/rpc/rpc_test.go
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
package rpc_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/amidaware/rmmagent/agent/tactical/rpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRunRPC(t *testing.T) {
|
||||||
|
testTable := []struct {
|
||||||
|
name string
|
||||||
|
expectedError error
|
||||||
|
version string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Run RPC",
|
||||||
|
expectedError: nil,
|
||||||
|
version: "development",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range testTable {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
err := rpc.RunRPC(tt.version)
|
||||||
|
if !errors.Is(tt.expectedError, err) {
|
||||||
|
t.Errorf("expected (%v), got (%v)", tt.expectedError, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -24,7 +24,7 @@ func RunAsService(version string) {
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func AgentSvc(version string) {
|
func AgentSvc(version string) error {
|
||||||
config := config.NewAgentConfig()
|
config := config.NewAgentConfig()
|
||||||
go shared.GetPython(false)
|
go shared.GetPython(false)
|
||||||
utils.CreateTRMMTempDir()
|
utils.CreateTRMMTempDir()
|
||||||
|
|
@ -35,6 +35,7 @@ func AgentSvc(version string) {
|
||||||
server := fmt.Sprintf("tls://%s:4222", config.APIURL)
|
server := fmt.Sprintf("tls://%s:4222", config.APIURL)
|
||||||
nc, err := nats.Connect(server, opts...)
|
nc, err := nats.Connect(server, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range natsCheckin {
|
for _, s := range natsCheckin {
|
||||||
|
|
|
||||||
36
agent/tactical/service/service_test.go
Normal file
36
agent/tactical/service/service_test.go
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
package service_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/amidaware/rmmagent/agent/tactical/service"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAgentSvc(t *testing.T) {
|
||||||
|
testTable := []struct {
|
||||||
|
name string
|
||||||
|
expectedError error
|
||||||
|
version string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Agent Svc",
|
||||||
|
expectedError: nil,
|
||||||
|
version: "2.0.4",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Agent Svc Error",
|
||||||
|
expectedError: nil,
|
||||||
|
version: "bad version",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range testTable {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
err := service.AgentSvc(tt.version)
|
||||||
|
if errors.Is(tt.expectedError, err) {
|
||||||
|
t.Errorf("expected (%v), got (%v)", tt.expectedError, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue