forked from goss-org/goss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddr.go
44 lines (37 loc) · 1.19 KB
/
addr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package resource
import (
"github.com/aelsabbahy/goss/system"
"github.com/aelsabbahy/goss/util"
)
type Addr struct {
Title string `json:"title,omitempty" yaml:"title,omitempty"`
Meta meta `json:"meta,omitempty" yaml:"meta,omitempty"`
Address string `json:"-" yaml:"-"`
Reachable matcher `json:"reachable" yaml:"reachable"`
Timeout int `json:"timeout" yaml:"timeout"`
}
func (a *Addr) ID() string { return a.Address }
func (a *Addr) SetID(id string) { a.Address = id }
// FIXME: Can this be refactored?
func (r *Addr) GetTitle() string { return r.Title }
func (r *Addr) GetMeta() meta { return r.Meta }
func (a *Addr) Validate(sys *system.System) []TestResult {
skip := false
if a.Timeout == 0 {
a.Timeout = 500
}
sysAddr := sys.NewAddr(a.Address, sys, util.Config{Timeout: a.Timeout})
var results []TestResult
results = append(results, ValidateValue(a, "reachable", a.Reachable, sysAddr.Reachable, skip))
return results
}
func NewAddr(sysAddr system.Addr, config util.Config) (*Addr, error) {
address := sysAddr.Address()
reachable, err := sysAddr.Reachable()
a := &Addr{
Address: address,
Reachable: reachable,
Timeout: config.Timeout,
}
return a, err
}