-
Notifications
You must be signed in to change notification settings - Fork 2
/
service.go
47 lines (40 loc) · 1.31 KB
/
service.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
45
46
47
package resource
import (
"github.com/SimonBaeumer/goss/system"
"github.com/SimonBaeumer/goss/util"
)
type Service struct {
Title string `json:"title,omitempty" yaml:"title,omitempty"`
Meta meta `json:"meta,omitempty" yaml:"meta,omitempty"`
Service string `json:"-" yaml:"-"`
Enabled matcher `json:"enabled" yaml:"enabled"`
Running matcher `json:"running" yaml:"running"`
}
func (s *Service) ID() string { return s.Service }
func (s *Service) SetID(id string) { s.Service = id }
func (s *Service) GetTitle() string { return s.Title }
func (s *Service) GetMeta() meta { return s.Meta }
func (s *Service) Validate(sys *system.System) []TestResult {
skip := false
sysservice := sys.NewService(s.Service, sys, util.Config{})
var results []TestResult
results = append(results, ValidateValue(s, "enabled", s.Enabled, sysservice.Enabled, skip))
results = append(results, ValidateValue(s, "running", s.Running, sysservice.Running, skip))
return results
}
func NewService(sysService system.Service, config util.Config) (*Service, error) {
service := sysService.Service()
enabled, err := sysService.Enabled()
if err != nil {
return nil, err
}
running, err := sysService.Running()
if err != nil {
return nil, err
}
return &Service{
Service: service,
Enabled: enabled,
Running: running,
}, nil
}