Skip to content

Commit 9313937

Browse files
committed
Use interface{}
1 parent fc02eff commit 9313937

38 files changed

+328
-99
lines changed

resource/addr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (a *Addr) Validate(sys *system.System) []TestResult {
5858
a.Timeout = 500
5959
}
6060

61-
sysAddr := sys.NewAddr(ctx, a.GetAddress(), sys, util.Config{Timeout: time.Duration(a.Timeout) * time.Millisecond, LocalAddress: a.LocalAddress})
61+
sysAddr, _ := sys.NewAddr(ctx, a.GetAddress(), sys, util.Config{Timeout: time.Duration(a.Timeout) * time.Millisecond, LocalAddress: a.LocalAddress})
6262

6363
var results []TestResult
6464
results = append(results, ValidateValue(a, "reachable", a.Reachable, sysAddr.Reachable, skip))

resource/command.go

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"fmt"
77
"io"
8+
"log"
89
"strings"
910
"time"
1011

@@ -41,11 +42,14 @@ func (c *Command) TypeName() string { return CommandResourceName }
4142

4243
func (c *Command) GetTitle() string { return c.Title }
4344
func (c *Command) GetMeta() meta { return c.Meta }
44-
func (c *Command) GetExec() util.ExecCommand {
45-
if c.Exec.CmdStr != "" || len(c.Exec.CmdSlice) > 0 {
46-
return c.Exec
45+
func (c *Command) GetExec() interface{} {
46+
if c.Exec.CmdStr != "" {
47+
return c.Exec.CmdStr
48+
} else if len(c.Exec.CmdSlice) > 0 {
49+
return c.Exec.CmdSlice
50+
} else {
51+
return util.ExecCommand{CmdStr: c.id}
4752
}
48-
return util.ExecCommand{CmdStr: c.id}
4953
}
5054

5155
func (c *Command) Validate(sys *system.System) []TestResult {
@@ -57,15 +61,34 @@ func (c *Command) Validate(sys *system.System) []TestResult {
5761
}
5862

5963
var results []TestResult
60-
sysCommand := sys.NewCommand(ctx, c.GetExec(), sys, util.Config{Timeout: time.Duration(c.Timeout) * time.Millisecond})
61-
62-
cExitStatus := deprecateAtoI(c.ExitStatus, fmt.Sprintf("%s: command.exit-status", c.ID()))
63-
results = append(results, ValidateValue(c, "exit-status", cExitStatus, sysCommand.ExitStatus, skip))
64-
if isSet(c.Stdout) {
65-
results = append(results, ValidateValue(c, "stdout", c.Stdout, sysCommand.Stdout, skip))
66-
}
67-
if isSet(c.Stderr) {
68-
results = append(results, ValidateValue(c, "stderr", c.Stderr, sysCommand.Stderr, skip))
64+
sysCommand, err := sys.NewCommand(ctx, c.GetExec(), sys, util.Config{Timeout: time.Duration(c.Timeout) * time.Millisecond})
65+
if err != nil {
66+
log.Printf("[ERROR] Could not create new command: %v", err)
67+
startTime := time.Now()
68+
results = append(
69+
results,
70+
TestResult{
71+
Result: FAIL,
72+
ResourceType: "Command",
73+
ResourceId: c.id,
74+
Title: c.Title,
75+
Meta: c.Meta,
76+
Property: "type",
77+
Err: toValidateError(err),
78+
StartTime: startTime,
79+
EndTime: startTime,
80+
Duration: startTime.Sub(startTime),
81+
},
82+
)
83+
} else {
84+
cExitStatus := deprecateAtoI(c.ExitStatus, fmt.Sprintf("%s: command.exit-status", c.ID()))
85+
results = append(results, ValidateValue(c, "exit-status", cExitStatus, sysCommand.ExitStatus, skip))
86+
if isSet(c.Stdout) {
87+
results = append(results, ValidateValue(c, "stdout", c.Stdout, sysCommand.Stdout, skip))
88+
}
89+
if isSet(c.Stderr) {
90+
results = append(results, ValidateValue(c, "stderr", c.Stderr, sysCommand.Stderr, skip))
91+
}
6992
}
7093
return results
7194
}

resource/dns.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (d *DNS) Validate(sys *system.System) []TestResult {
5858
d.Timeout = 500
5959
}
6060

61-
sysDNS := sys.NewDNS(ctx, d.GetResolve(), sys, util.Config{Timeout: time.Duration(d.Timeout) * time.Millisecond, Server: d.Server})
61+
sysDNS, _ := sys.NewDNS(ctx, d.GetResolve(), sys, util.Config{Timeout: time.Duration(d.Timeout) * time.Millisecond, Server: d.Server})
6262

6363
var results []TestResult
6464
// Backwards compatibility hack for now

resource/file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (f *File) GetPath() string {
6161
func (f *File) Validate(sys *system.System) []TestResult {
6262
ctx := context.WithValue(context.Background(), "id", f.ID())
6363
skip := f.Skip
64-
sysFile := sys.NewFile(ctx, f.GetPath(), sys, util.Config{})
64+
sysFile, _ := sys.NewFile(ctx, f.GetPath(), sys, util.Config{})
6565

6666
var results []TestResult
6767
results = append(results, ValidateValue(f, "exists", f.Exists, sysFile.Exists, skip))

resource/group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (g *Group) GetGroupname() string {
4949
func (g *Group) Validate(sys *system.System) []TestResult {
5050
ctx := context.WithValue(context.Background(), "id", g.ID())
5151
skip := g.Skip
52-
sysgroup := sys.NewGroup(ctx, g.GetGroupname(), sys, util.Config{})
52+
sysgroup, _ := sys.NewGroup(ctx, g.GetGroupname(), sys, util.Config{})
5353

5454
var results []TestResult
5555
results = append(results, ValidateValue(g, "exists", g.Exists, sysgroup.Exists, skip))

resource/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (u *HTTP) Validate(sys *system.System) []TestResult {
6868
if u.Timeout == 0 {
6969
u.Timeout = 5000
7070
}
71-
sysHTTP := sys.NewHTTP(ctx, u.getURL(), sys, util.Config{
71+
sysHTTP, _ := sys.NewHTTP(ctx, u.getURL(), sys, util.Config{
7272
AllowInsecure: u.AllowInsecure,
7373
CAFile: u.CAFile,
7474
CertFile: u.CertFile,

resource/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (i *Interface) GetName() string {
5252
func (i *Interface) Validate(sys *system.System) []TestResult {
5353
ctx := context.WithValue(context.Background(), "id", i.ID())
5454
skip := i.Skip
55-
sysInterface := sys.NewInterface(ctx, i.GetName(), sys, util.Config{})
55+
sysInterface, _ := sys.NewInterface(ctx, i.GetName(), sys, util.Config{})
5656

5757
var results []TestResult
5858
results = append(results, ValidateValue(i, "exists", i.Exists, sysInterface.Exists, skip))

resource/kernel_param.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (k *KernelParam) GetName() string {
5252
func (k *KernelParam) Validate(sys *system.System) []TestResult {
5353
ctx := context.WithValue(context.Background(), "id", k.ID())
5454
skip := k.Skip
55-
sysKernelParam := sys.NewKernelParam(ctx, k.GetName(), sys, util.Config{})
55+
sysKernelParam, _ := sys.NewKernelParam(ctx, k.GetName(), sys, util.Config{})
5656

5757
var results []TestResult
5858
results = append(results, ValidateValue(k, "value", k.Value, sysKernelParam.Value, skip))

resource/mount.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (m *Mount) GetMountPoint() string {
5555
func (m *Mount) Validate(sys *system.System) []TestResult {
5656
ctx := context.WithValue(context.Background(), "id", m.ID())
5757
skip := m.Skip
58-
sysMount := sys.NewMount(ctx, m.GetMountPoint(), sys, util.Config{})
58+
sysMount, _ := sys.NewMount(ctx, m.GetMountPoint(), sys, util.Config{})
5959

6060
var results []TestResult
6161
results = append(results, ValidateValue(m, "exists", m.Exists, sysMount.Exists, skip))

resource/package.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (p *Package) GetName() string {
4949
func (p *Package) Validate(sys *system.System) []TestResult {
5050
ctx := context.WithValue(context.Background(), "id", p.ID())
5151
skip := p.Skip
52-
sysPkg := sys.NewPackage(ctx, p.GetName(), sys, util.Config{})
52+
sysPkg, _ := sys.NewPackage(ctx, p.GetName(), sys, util.Config{})
5353

5454
var results []TestResult
5555
results = append(results, ValidateValue(p, "installed", p.Installed, sysPkg.Installed, skip))

resource/port.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (p *Port) GetPort() string {
4949
func (p *Port) Validate(sys *system.System) []TestResult {
5050
ctx := context.WithValue(context.Background(), "id", p.ID())
5151
skip := p.Skip
52-
sysPort := sys.NewPort(ctx, p.GetPort(), sys, util.Config{})
52+
sysPort, _ := sys.NewPort(ctx, p.GetPort(), sys, util.Config{})
5353

5454
var results []TestResult
5555
results = append(results, ValidateValue(p, "listening", p.Listening, sysPort.Listening, skip))

resource/process.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (p *Process) GetComm() string {
4848
func (p *Process) Validate(sys *system.System) []TestResult {
4949
ctx := context.WithValue(context.Background(), "id", p.ID())
5050
skip := p.Skip
51-
sysProcess := sys.NewProcess(ctx, p.GetComm(), sys, util.Config{})
51+
sysProcess, _ := sys.NewProcess(ctx, p.GetComm(), sys, util.Config{})
5252

5353
var results []TestResult
5454
results = append(results, ValidateValue(p, "running", p.Running, sysProcess.Running, skip))

0 commit comments

Comments
 (0)