Skip to content

Commit

Permalink
Added ctx object to all system struct's constructors (#837)
Browse files Browse the repository at this point in the history
* Added ctx object to all system struct's constructors

The idea behind this commit is to set the stage for adding aditional
logging metadata.

* Changed: Improved logging

* Added new flags `--log-level` and `-l` to be consistent with other goss
flags.
  * `--loglevel` and `-L` will be deprecated in a future release
* Log level accepts any casing, so DEBUG and debug are both valid cli opts
* Add log level support for `add` and `autoadd` commands

* Changed log time format to RFC3339
  • Loading branch information
aelsabbahy authored Sep 14, 2023
1 parent c673853 commit e6c727d
Show file tree
Hide file tree
Showing 43 changed files with 258 additions and 202 deletions.
6 changes: 5 additions & 1 deletion add.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
// AddResources is a simple wrapper to add multiple resources
func AddResources(fileName, resourceName string, keys []string, c *util.Config) error {
var err error
err = setLogLevel(c)
if err != nil {
return err
}
outStoreFormat, err = getStoreFormatFromFileName(fileName)
if err != nil {
return err
Expand Down Expand Up @@ -42,8 +46,8 @@ func AddResources(fileName, resourceName string, keys []string, c *util.Config)

// AddResource adds a single resource to fileName
func AddResource(fileName string, gossConfig GossConfig, resourceName, key string, config util.Config, sys *system.System) error {
var res resource.ResourceRead
var err error
var res resource.ResourceRead

// Need to figure out a good way to refactor this
switch resourceName {
Expand Down
4 changes: 2 additions & 2 deletions cmd/goss/goss.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func newRuntimeConfigFromCLI(c *cli.Context) *util.Config {
AnnounceToCLI: true,
Cache: c.Duration("cache"),
Debug: c.Bool("debug"),
LogLevel: c.GlobalString("loglevel"),
LogLevel: c.GlobalString("log-level"),
Endpoint: c.String("endpoint"),
FormatOptions: c.StringSlice("format-options"),
IgnoreList: c.GlobalStringSlice("exclude-attr"),
Expand Down Expand Up @@ -74,7 +74,7 @@ func main() {
app.Usage = "Quick and Easy server validation"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "loglevel, L",
Name: "log-level, loglevel, L, l",
Value: "FATAL",
Usage: "Goss log verbosity level",
EnvVar: "GOSS_LOGLEVEL",
Expand Down
26 changes: 0 additions & 26 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -53,9 +52,6 @@ github.com/icza/dyno v0.0.0-20230330125955-09f820a8d9c0/go.mod h1:c1tRKs5Tx7E2+u
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
Expand All @@ -75,15 +71,9 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/moby/sys/mountinfo v0.6.2 h1:BzJjoreD5BMFNmD9Rus6gdd1pLuecOFPt8wC+Vygl78=
github.com/moby/sys/mountinfo v0.6.2/go.mod h1:IJb6JQeOklcdMU9F5xQ8ZALD+CUr5VlGpwtX+VE0rpI=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/oleiade/reflections v1.0.1 h1:D1XO3LVEYroYskEsoSiGItp9RUxG6jWnCVvrqH0HHQM=
github.com/oleiade/reflections v1.0.1/go.mod h1:rdFxbxq4QXVZWj0F+e9jqjDkc7dbp97vkRixKo2JR60=
github.com/onsi/ginkgo/v2 v2.9.7 h1:06xGQy5www2oN160RtEZoTvnP2sPhEfePYmCDc2szss=
github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU=
github.com/onsi/gomega v1.27.8 h1:gegWiwZjBsf2DgiSbf5hpokZ98JVDMcWkUiigk6/KXc=
github.com/onsi/gomega v1.27.8/go.mod h1:2J8vzI/s+2shY9XHRApDkdgPo1TKT7P2u6fXeJKFnNQ=
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
Expand All @@ -99,8 +89,6 @@ github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUo
github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU=
github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY=
github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY=
github.com/prometheus/procfs v0.11.0 h1:5EAgkfkMl659uZPbe9AS2N68a7Cc1TJbPEuGzFuRbyk=
github.com/prometheus/procfs v0.11.0/go.mod h1:nwNm2aOCAYw8uTR/9bWRREkZFxAUcWzPHWJq+XBB/FM=
github.com/prometheus/procfs v0.11.1 h1:xRC8Iq1yyca5ypa9n1EZnWZkt7dwcoRPQwX/5gwaUuI=
github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/y0/p/ScXhY=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
Expand All @@ -125,8 +113,6 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/gjson v1.15.0 h1:5n/pM+v3r5ujuNl4YLZLsQ+UE5jlkLVm7jMzT5Mpolw=
github.com/tidwall/gjson v1.15.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
Expand All @@ -140,12 +126,8 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 h1:MGwJjxBy0HJshjDNfLsYO8xppfqWlA5ZT9OhtUUhTNw=
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b h1:r+vk0EmXNmekl0S0BascoeeoHk/L7wmaW2QF90K+kYI=
golang.org/x/exp v0.0.0-20230801115018-d63ba01acd4b/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
Expand All @@ -156,8 +138,6 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -172,8 +152,6 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand All @@ -183,16 +161,12 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8=
golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8=
golang.org/x/tools v0.11.1 h1:ojD5zOW8+7dOGzdnNgersm8aPfcDjhMp12UfG93NIMc=
golang.org/x/tools v0.11.1/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
31 changes: 20 additions & 11 deletions logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package goss

import (
"fmt"
"io"
"log"
"os"
"strings"
"time"

"github.com/goss-org/goss/util"
"github.com/hashicorp/logutils"
Expand All @@ -15,18 +18,24 @@ func setLogLevel(c *util.Config) error {
MinLevel: logutils.LogLevel("WARN"),
Writer: os.Stderr,
}
logLevelFound := false
log.SetFlags(0) // Turn off standard timestamp flags
log.SetOutput(&timestampedWriter{filter})
for _, lvl := range filter.Levels {
if string(lvl) == c.LogLevel {
logLevelFound = true
break
cLvl := strings.ToUpper(c.LogLevel)
if string(lvl) == cLvl {
filter.MinLevel = lvl
log.Printf("[DEBUG] Setting log level to %v", cLvl)
return nil
}
}
if !logLevelFound {
return fmt.Errorf("Unsupported log level: %s", c.LogLevel)
}
filter.MinLevel = logutils.LogLevel(c.LogLevel)
log.SetOutput(filter)
log.Printf("[DEBUG] Setting log level to %v", c.LogLevel)
return nil
return fmt.Errorf("Unsupported log level: %s", c.LogLevel)
}

type timestampedWriter struct {
wrappedWriter io.Writer
}

func (t *timestampedWriter) Write(b []byte) (int, error) {
timestamp := time.Now().UTC().Format(time.RFC3339)
return fmt.Fprintf(t.wrappedWriter, "%s %s", timestamp, b)
}
4 changes: 3 additions & 1 deletion resource/addr.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package resource

import (
"context"
"fmt"
"time"

Expand Down Expand Up @@ -50,13 +51,14 @@ func (a *Addr) GetAddress() string {
}

func (a *Addr) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", a.ID())
skip := a.Skip

if a.Timeout == 0 {
a.Timeout = 500
}

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

var results []TestResult
results = append(results, ValidateValue(a, "reachable", a.Reachable, sysAddr.Reachable, skip))
Expand Down
4 changes: 3 additions & 1 deletion resource/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resource

import (
"bufio"
"context"
"fmt"
"io"
"strings"
Expand Down Expand Up @@ -48,14 +49,15 @@ func (c *Command) GetExec() string {
}

func (c *Command) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", c.ID())
skip := c.Skip

if c.Timeout == 0 {
c.Timeout = 10000
}

var results []TestResult
sysCommand := sys.NewCommand(c.GetExec(), sys, util.Config{Timeout: time.Duration(c.Timeout) * time.Millisecond})
sysCommand := sys.NewCommand(ctx, c.GetExec(), sys, util.Config{Timeout: time.Duration(c.Timeout) * time.Millisecond})

cExitStatus := deprecateAtoI(c.ExitStatus, fmt.Sprintf("%s: command.exit-status", c.ID()))
results = append(results, ValidateValue(c, "exit-status", cExitStatus, sysCommand.ExitStatus, skip))
Expand Down
4 changes: 3 additions & 1 deletion resource/dns.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package resource

import (
"context"
"fmt"
"strings"
"time"
Expand Down Expand Up @@ -51,12 +52,13 @@ func (d *DNS) GetResolve() string {
}

func (d *DNS) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", d.ID())
skip := d.Skip
if d.Timeout == 0 {
d.Timeout = 500
}

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

var results []TestResult
// Backwards compatibility hack for now
Expand Down
4 changes: 3 additions & 1 deletion resource/file.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package resource

import (
"context"
"fmt"
"os"

Expand Down Expand Up @@ -58,8 +59,9 @@ func (f *File) GetPath() string {
}

func (f *File) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", f.ID())
skip := f.Skip
sysFile := sys.NewFile(f.GetPath(), sys, util.Config{})
sysFile := sys.NewFile(ctx, f.GetPath(), sys, util.Config{})

var results []TestResult
results = append(results, ValidateValue(f, "exists", f.Exists, sysFile.Exists, skip))
Expand Down
4 changes: 3 additions & 1 deletion resource/group.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package resource

import (
"context"
"fmt"

"github.com/goss-org/goss/system"
Expand Down Expand Up @@ -46,8 +47,9 @@ func (g *Group) GetGroupname() string {
}

func (g *Group) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", g.ID())
skip := g.Skip
sysgroup := sys.NewGroup(g.GetGroupname(), sys, util.Config{})
sysgroup := sys.NewGroup(ctx, g.GetGroupname(), sys, util.Config{})

var results []TestResult
results = append(results, ValidateValue(g, "exists", g.Exists, sysgroup.Exists, skip))
Expand Down
4 changes: 3 additions & 1 deletion resource/http.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package resource

import (
"context"
"fmt"
"time"

Expand Down Expand Up @@ -62,11 +63,12 @@ func (r *HTTP) getURL() string {
}

func (u *HTTP) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", u.ID())
skip := u.Skip
if u.Timeout == 0 {
u.Timeout = 5000
}
sysHTTP := sys.NewHTTP(u.getURL(), sys, util.Config{
sysHTTP := sys.NewHTTP(ctx, u.getURL(), sys, util.Config{
AllowInsecure: u.AllowInsecure,
CAFile: u.CAFile,
CertFile: u.CertFile,
Expand Down
4 changes: 3 additions & 1 deletion resource/interface.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package resource

import (
"context"
"fmt"

"github.com/goss-org/goss/system"
Expand Down Expand Up @@ -49,8 +50,9 @@ func (i *Interface) GetName() string {
}

func (i *Interface) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", i.ID())
skip := i.Skip
sysInterface := sys.NewInterface(i.GetName(), sys, util.Config{})
sysInterface := sys.NewInterface(ctx, i.GetName(), sys, util.Config{})

var results []TestResult
results = append(results, ValidateValue(i, "exists", i.Exists, sysInterface.Exists, skip))
Expand Down
4 changes: 3 additions & 1 deletion resource/kernel_param.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package resource

import (
"context"
"fmt"

"github.com/goss-org/goss/system"
Expand Down Expand Up @@ -49,8 +50,9 @@ func (k *KernelParam) GetName() string {
}

func (k *KernelParam) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", k.ID())
skip := k.Skip
sysKernelParam := sys.NewKernelParam(k.GetName(), sys, util.Config{})
sysKernelParam := sys.NewKernelParam(ctx, k.GetName(), sys, util.Config{})

var results []TestResult
results = append(results, ValidateValue(k, "value", k.Value, sysKernelParam.Value, skip))
Expand Down
4 changes: 3 additions & 1 deletion resource/mount.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package resource

import (
"context"
"fmt"

"github.com/goss-org/goss/system"
Expand Down Expand Up @@ -52,8 +53,9 @@ func (m *Mount) GetMountPoint() string {
}

func (m *Mount) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", m.ID())
skip := m.Skip
sysMount := sys.NewMount(m.GetMountPoint(), sys, util.Config{})
sysMount := sys.NewMount(ctx, m.GetMountPoint(), sys, util.Config{})

var results []TestResult
results = append(results, ValidateValue(m, "exists", m.Exists, sysMount.Exists, skip))
Expand Down
4 changes: 3 additions & 1 deletion resource/package.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package resource

import (
"context"
"fmt"

"github.com/goss-org/goss/system"
Expand Down Expand Up @@ -46,8 +47,9 @@ func (p *Package) GetName() string {
}

func (p *Package) Validate(sys *system.System) []TestResult {
ctx := context.WithValue(context.Background(), "id", p.ID())
skip := p.Skip
sysPkg := sys.NewPackage(p.GetName(), sys, util.Config{})
sysPkg := sys.NewPackage(ctx, p.GetName(), sys, util.Config{})

var results []TestResult
results = append(results, ValidateValue(p, "installed", p.Installed, sysPkg.Installed, skip))
Expand Down
Loading

0 comments on commit e6c727d

Please sign in to comment.