forked from goss-org/goss
/
mount.go
69 lines (62 loc) · 2.04 KB
/
mount.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package resource
import (
"github.com/aelsabbahy/goss/system"
"github.com/aelsabbahy/goss/util"
)
type Mount struct {
Title string `json:"title,omitempty" yaml:"title,omitempty"`
Meta meta `json:"meta,omitempty" yaml:"meta,omitempty"`
MountPoint string `json:"-" yaml:"-"`
Exists matcher `json:"exists" yaml:"exists"`
Opts matcher `json:"opts,omitempty" yaml:"opts,omitempty"`
Source matcher `json:"source,omitempty" yaml:"source,omitempty"`
Filesystem matcher `json:"filesystem,omitempty" yaml:"filesystem,omitempty"`
}
func (m *Mount) ID() string { return m.MountPoint }
func (m *Mount) SetID(id string) { m.MountPoint = id }
// FIXME: Can this be refactored?
func (m *Mount) GetTitle() string { return m.Title }
func (m *Mount) GetMeta() meta { return m.Meta }
func (m *Mount) Validate(sys *system.System) []TestResult {
skip := false
sysMount := sys.NewMount(m.MountPoint, sys, util.Config{})
var results []TestResult
results = append(results, ValidateValue(m, "exists", m.Exists, sysMount.Exists, skip))
if shouldSkip(results) {
skip = true
}
if m.Opts != nil {
results = append(results, ValidateValue(m, "opts", m.Opts, sysMount.Opts, skip))
}
if m.Source != nil {
results = append(results, ValidateValue(m, "source", m.Source, sysMount.Source, skip))
}
if m.Filesystem != nil {
results = append(results, ValidateValue(m, "filesystem", m.Filesystem, sysMount.Filesystem, skip))
}
return results
}
func NewMount(sysMount system.Mount, config util.Config) (*Mount, error) {
mountPoint := sysMount.MountPoint()
exists, _ := sysMount.Exists()
m := &Mount{
MountPoint: mountPoint,
Exists: exists,
}
if !contains(config.IgnoreList, "opts") {
if opts, err := sysMount.Opts(); err == nil {
m.Opts = opts
}
}
if !contains(config.IgnoreList, "source") {
if source, err := sysMount.Source(); err == nil {
m.Source = source
}
}
if !contains(config.IgnoreList, "filesystem") {
if filesystem, err := sysMount.Filesystem(); err == nil {
m.Filesystem = filesystem
}
}
return m, nil
}