diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml index 9ec7ec636..7bbb5cd9a 100644 --- a/.github/workflows/golangci-lint.yaml +++ b/.github/workflows/golangci-lint.yaml @@ -23,5 +23,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: - version: latest - only-new-issues: true + version: v1.59 diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 000000000..52977cfd6 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,16 @@ +linters: + # Disable all linters. + # Default: false + disable-all: true + # Enable specific linter + # https://golangci-lint.run/usage/linters/#enabled-by-default + enable: + # default linter + # - errcheck # there are to many failures at the moment + - gosimple + - govet + - ineffassign + - staticcheck + - unused + # custom linter + - gofmt diff --git a/Makefile b/Makefile index 6d4cf159c..d45d21084 100644 --- a/Makefile +++ b/Makefile @@ -35,10 +35,10 @@ htmlcov: go test -v -coverpkg=./... -coverprofile=c.out ./... go tool cover -html ./c.out - lint: $(info INFO: Starting build $@) - golint $(pkgs) || true + go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59 + golangci-lint run --timeout 5m $(pkgs) || true vet: $(info INFO: Starting build $@) diff --git a/cmd/goss/goss.go b/cmd/goss/goss.go index e7ff90540..0c6a061a2 100644 --- a/cmd/goss/goss.go +++ b/cmd/goss/goss.go @@ -423,14 +423,6 @@ func addAlphaFlagIfNeeded(app *cli.App) { } } -const msgFormat string = `WARNING: goss for this platform (%q) is alpha-quality, work-in-progress and community-supported. - -You should not expect everything to work. Treat linux as the canonical behaviour to expect. - -Please see https://github.com/goss-org/goss/tree/master/docs/platform-feature-parity.md to set your expectations and see progress. -Please file issues via https://github.com/goss-org/goss/issues/new/choose -Pull requests and bug reports very welcome.` - func fatalAlphaIfNeeded(c *cli.Context) { if runtime.GOOS == "darwin" || runtime.GOOS == "windows" { if c.GlobalString("use-alpha") != "1" { diff --git a/integration-tests/Dockerfile_alpine3 b/integration-tests/Dockerfile_alpine3 index 153bc0c68..48713ceeb 100644 --- a/integration-tests/Dockerfile_alpine3 +++ b/integration-tests/Dockerfile_alpine3 @@ -1,9 +1,9 @@ -FROM alpine:3.12 +FROM alpine:3.19 MAINTAINER Ahmed # install apache2 and remove un-needed services RUN apk update && \ - apk add openrc apache2 bash ca-certificates tinyproxy && \ + apk add --no-cache openrc apache2=2.4.59-r0 bash ca-certificates tinyproxy && \ rc-update add apache2 && \ rc-update add tinyproxy && \ rm -rf /etc/init.d/networking /etc/init.d/hwdrivers /var/cache/apk/* /tmp/* diff --git a/integration-tests/goss/alpine3/goss-aa-expected.yaml b/integration-tests/goss/alpine3/goss-aa-expected.yaml index 2d95f3e6b..ea7c1180b 100644 --- a/integration-tests/goss/alpine3/goss-aa-expected.yaml +++ b/integration-tests/goss/alpine3/goss-aa-expected.yaml @@ -2,7 +2,7 @@ package: apache2: installed: true versions: - - 2.4.46-r1 + - 2.4.59-r0 service: apache2: enabled: true diff --git a/integration-tests/goss/alpine3/goss-expected.yaml b/integration-tests/goss/alpine3/goss-expected.yaml index 0953e91d8..b3fc9f83e 100644 --- a/integration-tests/goss/alpine3/goss-expected.yaml +++ b/integration-tests/goss/alpine3/goss-expected.yaml @@ -13,7 +13,7 @@ package: apache2: installed: true versions: - - 2.4.46-r1 + - 2.4.59-r0 foobar: installed: false vim-tiny: diff --git a/integration-tests/goss/vars.yaml b/integration-tests/goss/vars.yaml index cbf6df778..dd505182b 100644 --- a/integration-tests/goss/vars.yaml +++ b/integration-tests/goss/vars.yaml @@ -2,7 +2,7 @@ alpine3: proxy: http://127.0.0.1:8888 packages: - apache2: "2.4.46-r1" + apache2: "2.4.59-r0" services: apache2: [sysinit] arch: diff --git a/matchers/have_patterns.go b/matchers/have_patterns.go index fd7c92897..cf2bcd139 100644 --- a/matchers/have_patterns.go +++ b/matchers/have_patterns.go @@ -146,14 +146,6 @@ func (m *HavePatternsMatcher) NegatedFailureResult(actual interface{}) MatcherRe } } -func appendMissingStrings(message string, missingElements []string) string { - if len(missingElements) == 0 { - return message - } - return fmt.Sprintf("%s\nthe missing elements were\n%s", message, - format.Object(missingElements, 1)) -} - type patternMatcher interface { Match(string) bool Pattern() string diff --git a/matchers/type_conversion.go b/matchers/type_conversion.go index 0d425bb4f..29fb96db8 100644 --- a/matchers/type_conversion.go +++ b/matchers/type_conversion.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "strconv" "strings" @@ -108,7 +107,7 @@ func (t ReaderToString) Transform(i interface{}) (interface{}, error) { return nil, fmt.Errorf("Expected io.reader, Got:%s", format.Object(i, 1)) } - b, err := ioutil.ReadAll(r) + b, err := io.ReadAll(r) if err != nil { return "", err } diff --git a/outputs/json.go b/outputs/json.go index 0d7063d0c..c2413aaf4 100644 --- a/outputs/json.go +++ b/outputs/json.go @@ -24,8 +24,7 @@ func (r Json) ValidOptions() []*formatOption { func (r Json) Output(w io.Writer, results <-chan []resource.TestResult, outConfig util.OutputConfig) (exitCode int) { - var pretty bool - pretty = util.IsValueInList(foPretty, outConfig.FormatOptions) + var pretty bool = util.IsValueInList(foPretty, outConfig.FormatOptions) includeRaw := !util.IsValueInList(foExcludeRaw, outConfig.FormatOptions) sort := util.IsValueInList(foSort, outConfig.FormatOptions) diff --git a/outputs/junit.go b/outputs/junit.go index 3e7de6ead..d50e3677e 100644 --- a/outputs/junit.go +++ b/outputs/junit.go @@ -34,8 +34,7 @@ func (r JUnit) Output(w io.Writer, results <-chan []resource.TestResult, // ISO8601 timeformat timestamp := time.Now().Format(time.RFC3339) - var summary map[int]string - summary = make(map[int]string) + var summary map[int]string = make(map[int]string) var startTime time.Time var endTime time.Time diff --git a/outputs/nagios.go b/outputs/nagios.go index d91776dba..2940d2235 100644 --- a/outputs/nagios.go +++ b/outputs/nagios.go @@ -31,8 +31,7 @@ func (r Nagios) Output(w io.Writer, results <-chan []resource.TestResult, var startTime time.Time var endTime time.Time - var summary map[int]string - summary = make(map[int]string) + var summary map[int]string = make(map[int]string) for resultGroup := range results { for _, testResult := range resultGroup { diff --git a/outputs/rspecish.go b/outputs/rspecish.go index cdeae891f..7fb5f2f9f 100644 --- a/outputs/rspecish.go +++ b/outputs/rspecish.go @@ -43,15 +43,15 @@ func (r Rspecish) Output(w io.Writer, results <-chan []resource.TestResult, switch testResult.Result { case resource.SUCCESS: logTrace("TRACE", "SUCCESS", testResult, false) - fmt.Fprintf(w, green(".")) + fmt.Fprint(w, green(".")) case resource.SKIP: logTrace("TRACE", "SKIP", testResult, false) - fmt.Fprintf(w, yellow("S")) + fmt.Fprint(w, yellow("S")) failedOrSkippedGroup = append(failedOrSkippedGroup, testResult) skipped++ case resource.FAIL: logTrace("TRACE", "FAIL", testResult, false) - fmt.Fprintf(w, red("F")) + fmt.Fprint(w, red("F")) failedOrSkippedGroup = append(failedOrSkippedGroup, testResult) failed++ } diff --git a/outputs/tap.go b/outputs/tap.go index 341e2a0ef..a5d6166ca 100644 --- a/outputs/tap.go +++ b/outputs/tap.go @@ -27,8 +27,7 @@ func (r Tap) Output(w io.Writer, results <-chan []resource.TestResult, testCount := 0 failed := 0 - var summary map[int]string - summary = make(map[int]string) + var summary map[int]string = make(map[int]string) for resultGroup := range results { for _, testResult := range resultGroup { diff --git a/resource/addr.go b/resource/addr.go index 2347583e9..f98eb630f 100644 --- a/resource/addr.go +++ b/resource/addr.go @@ -20,6 +20,8 @@ type Addr struct { Skip bool `json:"skip,omitempty" yaml:"skip,omitempty"` } +type idKey struct{} + const ( AddrResourceKey = "addr" AddResourceName = "Addr" @@ -51,7 +53,7 @@ func (a *Addr) GetAddress() string { } func (a *Addr) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", a.ID()) + ctx := context.WithValue(context.Background(), idKey{}, a.ID()) skip := a.Skip if a.Timeout == 0 { diff --git a/resource/command.go b/resource/command.go index 79a1671e7..365867d24 100644 --- a/resource/command.go +++ b/resource/command.go @@ -49,7 +49,7 @@ func (c *Command) GetExec() string { } func (c *Command) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", c.ID()) + ctx := context.WithValue(context.Background(), idKey{}, c.ID()) skip := c.Skip if c.Timeout == 0 { diff --git a/resource/dns.go b/resource/dns.go index bd3274d99..6cd114002 100644 --- a/resource/dns.go +++ b/resource/dns.go @@ -52,7 +52,7 @@ func (d *DNS) GetResolve() string { } func (d *DNS) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", d.ID()) + ctx := context.WithValue(context.Background(), idKey{}, d.ID()) skip := d.Skip if d.Timeout == 0 { d.Timeout = 500 diff --git a/resource/file.go b/resource/file.go index 97356a193..6b3c94c4c 100644 --- a/resource/file.go +++ b/resource/file.go @@ -61,7 +61,7 @@ func (f *File) GetPath() string { } func (f *File) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", f.ID()) + ctx := context.WithValue(context.Background(), idKey{}, f.ID()) skip := f.Skip sysFile := sys.NewFile(ctx, f.GetPath(), sys, util.Config{}) diff --git a/resource/group.go b/resource/group.go index 7ca928108..cfd71a3a3 100644 --- a/resource/group.go +++ b/resource/group.go @@ -47,7 +47,7 @@ func (g *Group) GetGroupname() string { } func (g *Group) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", g.ID()) + ctx := context.WithValue(context.Background(), idKey{}, g.ID()) skip := g.Skip sysgroup := sys.NewGroup(ctx, g.GetGroupname(), sys, util.Config{}) diff --git a/resource/http.go b/resource/http.go index b9a1006de..bbd820098 100644 --- a/resource/http.go +++ b/resource/http.go @@ -63,7 +63,7 @@ func (r *HTTP) getURL() string { } func (u *HTTP) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", u.ID()) + ctx := context.WithValue(context.Background(), idKey{}, u.ID()) skip := u.Skip if u.Timeout == 0 { u.Timeout = 5000 diff --git a/resource/interface.go b/resource/interface.go index 14921d133..68e3fa3d6 100644 --- a/resource/interface.go +++ b/resource/interface.go @@ -50,7 +50,7 @@ func (i *Interface) GetName() string { } func (i *Interface) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", i.ID()) + ctx := context.WithValue(context.Background(), idKey{}, i.ID()) skip := i.Skip sysInterface := sys.NewInterface(ctx, i.GetName(), sys, util.Config{}) diff --git a/resource/kernel_param.go b/resource/kernel_param.go index 494597a96..7f50270bd 100644 --- a/resource/kernel_param.go +++ b/resource/kernel_param.go @@ -50,7 +50,7 @@ func (k *KernelParam) GetName() string { } func (k *KernelParam) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", k.ID()) + ctx := context.WithValue(context.Background(), idKey{}, k.ID()) skip := k.Skip sysKernelParam := sys.NewKernelParam(ctx, k.GetName(), sys, util.Config{}) diff --git a/resource/mount.go b/resource/mount.go index 401c172ec..4410cbb2f 100644 --- a/resource/mount.go +++ b/resource/mount.go @@ -54,7 +54,7 @@ func (m *Mount) GetMountPoint() string { } func (m *Mount) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", m.ID()) + ctx := context.WithValue(context.Background(), idKey{}, m.ID()) skip := m.Skip if m.Timeout == 0 { diff --git a/resource/package.go b/resource/package.go index f8afffcb5..6d393a1b2 100644 --- a/resource/package.go +++ b/resource/package.go @@ -47,7 +47,7 @@ func (p *Package) GetName() string { } func (p *Package) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", p.ID()) + ctx := context.WithValue(context.Background(), idKey{}, p.ID()) skip := p.Skip sysPkg := sys.NewPackage(ctx, p.GetName(), sys, util.Config{}) diff --git a/resource/port.go b/resource/port.go index 70f72ae93..02c32859c 100644 --- a/resource/port.go +++ b/resource/port.go @@ -47,7 +47,7 @@ func (p *Port) GetPort() string { } func (p *Port) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", p.ID()) + ctx := context.WithValue(context.Background(), idKey{}, p.ID()) skip := p.Skip sysPort := sys.NewPort(ctx, p.GetPort(), sys, util.Config{}) diff --git a/resource/process.go b/resource/process.go index 9012760e9..c7413d7ef 100644 --- a/resource/process.go +++ b/resource/process.go @@ -46,7 +46,7 @@ func (p *Process) GetComm() string { } func (p *Process) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", p.ID()) + ctx := context.WithValue(context.Background(), idKey{}, p.ID()) skip := p.Skip sysProcess := sys.NewProcess(ctx, p.GetComm(), sys, util.Config{}) diff --git a/resource/resource.go b/resource/resource.go index bff257e02..104972ad5 100644 --- a/resource/resource.go +++ b/resource/resource.go @@ -5,11 +5,9 @@ import ( "os" "path/filepath" "strconv" - "strings" "sync" "github.com/goss-org/goss/system" - "github.com/oleiade/reflections" ) type Resource interface { @@ -66,18 +64,6 @@ func deprecateAtoI(depr any, desc string) any { return float64(i) } -func validAttrs(i any, t string) (map[string]bool, error) { - validAttrs := make(map[string]bool) - tags, err := reflections.Tags(i, t) - if err != nil { - return nil, err - } - for _, v := range tags { - validAttrs[strings.Split(v, ",")[0]] = true - } - return validAttrs, nil -} - func shouldSkip(results []TestResult) bool { if len(results) < 1 { return false diff --git a/resource/resource_list.go b/resource/resource_list.go index e3aedb633..61b381596 100644 --- a/resource/resource_list.go +++ b/resource/resource_list.go @@ -18,7 +18,7 @@ import ( type AddrMap map[string]*Addr func (r AddrMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Addr, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewAddr(ctx, sr, sys, config) res, err := NewAddr(sysres, config) if err != nil { @@ -33,13 +33,13 @@ func (r AddrMap) AppendSysResource(sr string, sys *system.System, config util.Co } func (r AddrMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Addr, system.Addr, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewAddr(ctx, sr, sys, util.Config{}) res, err := NewAddr(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -119,7 +119,7 @@ func (ret *AddrMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type CommandMap map[string]*Command func (r CommandMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Command, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewCommand(ctx, sr, sys, config) res, err := NewCommand(sysres, config) if err != nil { @@ -134,13 +134,13 @@ func (r CommandMap) AppendSysResource(sr string, sys *system.System, config util } func (r CommandMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Command, system.Command, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewCommand(ctx, sr, sys, util.Config{}) res, err := NewCommand(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -220,7 +220,7 @@ func (ret *CommandMap) UnmarshalYAML(unmarshal func(v interface{}) error) error type DNSMap map[string]*DNS func (r DNSMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*DNS, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewDNS(ctx, sr, sys, config) res, err := NewDNS(sysres, config) if err != nil { @@ -235,13 +235,13 @@ func (r DNSMap) AppendSysResource(sr string, sys *system.System, config util.Con } func (r DNSMap) AppendSysResourceIfExists(sr string, sys *system.System) (*DNS, system.DNS, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewDNS(ctx, sr, sys, util.Config{}) res, err := NewDNS(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -321,7 +321,7 @@ func (ret *DNSMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type FileMap map[string]*File func (r FileMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*File, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewFile(ctx, sr, sys, config) res, err := NewFile(sysres, config) if err != nil { @@ -336,13 +336,13 @@ func (r FileMap) AppendSysResource(sr string, sys *system.System, config util.Co } func (r FileMap) AppendSysResourceIfExists(sr string, sys *system.System) (*File, system.File, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewFile(ctx, sr, sys, util.Config{}) res, err := NewFile(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -422,7 +422,7 @@ func (ret *FileMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type GossfileMap map[string]*Gossfile func (r GossfileMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Gossfile, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewGossfile(ctx, sr, sys, config) res, err := NewGossfile(sysres, config) if err != nil { @@ -437,13 +437,13 @@ func (r GossfileMap) AppendSysResource(sr string, sys *system.System, config uti } func (r GossfileMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Gossfile, system.Gossfile, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewGossfile(ctx, sr, sys, util.Config{}) res, err := NewGossfile(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -523,7 +523,7 @@ func (ret *GossfileMap) UnmarshalYAML(unmarshal func(v interface{}) error) error type GroupMap map[string]*Group func (r GroupMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Group, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewGroup(ctx, sr, sys, config) res, err := NewGroup(sysres, config) if err != nil { @@ -538,13 +538,13 @@ func (r GroupMap) AppendSysResource(sr string, sys *system.System, config util.C } func (r GroupMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Group, system.Group, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewGroup(ctx, sr, sys, util.Config{}) res, err := NewGroup(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -624,7 +624,7 @@ func (ret *GroupMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type PackageMap map[string]*Package func (r PackageMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Package, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewPackage(ctx, sr, sys, config) res, err := NewPackage(sysres, config) if err != nil { @@ -639,13 +639,13 @@ func (r PackageMap) AppendSysResource(sr string, sys *system.System, config util } func (r PackageMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Package, system.Package, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewPackage(ctx, sr, sys, util.Config{}) res, err := NewPackage(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -725,7 +725,7 @@ func (ret *PackageMap) UnmarshalYAML(unmarshal func(v interface{}) error) error type PortMap map[string]*Port func (r PortMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Port, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewPort(ctx, sr, sys, config) res, err := NewPort(sysres, config) if err != nil { @@ -740,13 +740,13 @@ func (r PortMap) AppendSysResource(sr string, sys *system.System, config util.Co } func (r PortMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Port, system.Port, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewPort(ctx, sr, sys, util.Config{}) res, err := NewPort(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -826,7 +826,7 @@ func (ret *PortMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type ProcessMap map[string]*Process func (r ProcessMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Process, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewProcess(ctx, sr, sys, config) res, err := NewProcess(sysres, config) if err != nil { @@ -841,13 +841,13 @@ func (r ProcessMap) AppendSysResource(sr string, sys *system.System, config util } func (r ProcessMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Process, system.Process, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewProcess(ctx, sr, sys, util.Config{}) res, err := NewProcess(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -927,7 +927,7 @@ func (ret *ProcessMap) UnmarshalYAML(unmarshal func(v interface{}) error) error type ServiceMap map[string]*Service func (r ServiceMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Service, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewService(ctx, sr, sys, config) res, err := NewService(sysres, config) if err != nil { @@ -942,13 +942,13 @@ func (r ServiceMap) AppendSysResource(sr string, sys *system.System, config util } func (r ServiceMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Service, system.Service, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewService(ctx, sr, sys, util.Config{}) res, err := NewService(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -1028,7 +1028,7 @@ func (ret *ServiceMap) UnmarshalYAML(unmarshal func(v interface{}) error) error type UserMap map[string]*User func (r UserMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*User, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewUser(ctx, sr, sys, config) res, err := NewUser(sysres, config) if err != nil { @@ -1043,13 +1043,13 @@ func (r UserMap) AppendSysResource(sr string, sys *system.System, config util.Co } func (r UserMap) AppendSysResourceIfExists(sr string, sys *system.System) (*User, system.User, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewUser(ctx, sr, sys, util.Config{}) res, err := NewUser(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -1129,7 +1129,7 @@ func (ret *UserMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type KernelParamMap map[string]*KernelParam func (r KernelParamMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*KernelParam, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewKernelParam(ctx, sr, sys, config) res, err := NewKernelParam(sysres, config) if err != nil { @@ -1144,13 +1144,13 @@ func (r KernelParamMap) AppendSysResource(sr string, sys *system.System, config } func (r KernelParamMap) AppendSysResourceIfExists(sr string, sys *system.System) (*KernelParam, system.KernelParam, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewKernelParam(ctx, sr, sys, util.Config{}) res, err := NewKernelParam(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -1230,7 +1230,7 @@ func (ret *KernelParamMap) UnmarshalYAML(unmarshal func(v interface{}) error) er type MountMap map[string]*Mount func (r MountMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Mount, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewMount(ctx, sr, sys, config) res, err := NewMount(sysres, config) if err != nil { @@ -1245,13 +1245,13 @@ func (r MountMap) AppendSysResource(sr string, sys *system.System, config util.C } func (r MountMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Mount, system.Mount, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewMount(ctx, sr, sys, util.Config{}) res, err := NewMount(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -1331,7 +1331,7 @@ func (ret *MountMap) UnmarshalYAML(unmarshal func(v interface{}) error) error { type InterfaceMap map[string]*Interface func (r InterfaceMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*Interface, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewInterface(ctx, sr, sys, config) res, err := NewInterface(sysres, config) if err != nil { @@ -1346,13 +1346,13 @@ func (r InterfaceMap) AppendSysResource(sr string, sys *system.System, config ut } func (r InterfaceMap) AppendSysResourceIfExists(sr string, sys *system.System) (*Interface, system.Interface, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewInterface(ctx, sr, sys, util.Config{}) res, err := NewInterface(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { @@ -1432,7 +1432,7 @@ func (ret *InterfaceMap) UnmarshalYAML(unmarshal func(v interface{}) error) erro type HTTPMap map[string]*HTTP func (r HTTPMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*HTTP, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewHTTP(ctx, sr, sys, config) res, err := NewHTTP(sysres, config) if err != nil { @@ -1447,13 +1447,13 @@ func (r HTTPMap) AppendSysResource(sr string, sys *system.System, config util.Co } func (r HTTPMap) AppendSysResourceIfExists(sr string, sys *system.System) (*HTTP, system.HTTP, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewHTTP(ctx, sr, sys, util.Config{}) res, err := NewHTTP(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { diff --git a/resource/resource_list_genny.go b/resource/resource_list_genny.go index a483bc4ea..fccdea348 100644 --- a/resource/resource_list_genny.go +++ b/resource/resource_list_genny.go @@ -26,7 +26,7 @@ type ResourceType generic.Type type ResourceTypeMap map[string]*ResourceType func (r ResourceTypeMap) AppendSysResource(sr string, sys *system.System, config util.Config) (*ResourceType, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewResourceType(ctx, sr, sys, config) res, err := NewResourceType(sysres, config) if err != nil { @@ -41,13 +41,13 @@ func (r ResourceTypeMap) AppendSysResource(sr string, sys *system.System, config } func (r ResourceTypeMap) AppendSysResourceIfExists(sr string, sys *system.System) (*ResourceType, system.ResourceType, bool, error) { - ctx := context.WithValue(context.Background(), "id", sr) + ctx := context.WithValue(context.Background(), idKey{}, sr) sysres := sys.NewResourceType(ctx, sr, sys, util.Config{}) res, err := NewResourceType(sysres, util.Config{}) if err != nil { return nil, nil, false, err } - if e, _ := sysres.Exists(); e != true { + if e, _ := sysres.Exists(); !e { return res, sysres, false, nil } if old_res, ok := r[res.ID()]; ok { diff --git a/resource/service.go b/resource/service.go index 2285c3e1f..2f35e9d3d 100644 --- a/resource/service.go +++ b/resource/service.go @@ -48,7 +48,7 @@ func (s *Service) GetName() string { } func (s *Service) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", s.ID()) + ctx := context.WithValue(context.Background(), idKey{}, s.ID()) skip := s.Skip sysservice := sys.NewService(ctx, s.GetName(), sys, util.Config{}) diff --git a/resource/user.go b/resource/user.go index 3895f8067..c1b64b06f 100644 --- a/resource/user.go +++ b/resource/user.go @@ -51,7 +51,7 @@ func (u *User) GetUsername() string { } func (u *User) Validate(sys *system.System) []TestResult { - ctx := context.WithValue(context.Background(), "id", u.ID()) + ctx := context.WithValue(context.Background(), idKey{}, u.ID()) skip := u.Skip sysuser := sys.NewUser(ctx, u.GetUsername(), sys, util.Config{}) diff --git a/resource/validate.go b/resource/validate.go index c7abb4428..720c7b7d5 100644 --- a/resource/validate.go +++ b/resource/validate.go @@ -41,10 +41,6 @@ func HumanOutcomes() map[int]string { return humanOutcomes } -const ( - maxScanTokenSize = 10 * 1024 * 1024 -) - type ValidateError string func (g ValidateError) Error() string { return string(g) } diff --git a/serve.go b/serve.go index 3adb34270..d30973adf 100644 --- a/serve.go +++ b/serve.go @@ -85,7 +85,7 @@ func (h healthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { log.Printf("[TRACE] %v: requesting health probe", r.RemoteAddr) resp := h.processAndEnsureCached(negotiatedContentType, outputer) - w.Header().Set(http.CanonicalHeaderKey("Content-Type"), negotiatedContentType) + w.Header().Set(http.CanonicalHeaderKey("Content-Type"), negotiatedContentType) //nolint:gosimple w.WriteHeader(resp.statusCode) logBody := "" if resp.statusCode != http.StatusOK { diff --git a/serve_test.go b/serve_test.go index b29fe3baf..8b19d048d 100644 --- a/serve_test.go +++ b/serve_test.go @@ -66,7 +66,7 @@ func TestServeWithNoContentNegotiation(t *testing.T) { t.Logf("testName %q log output:\n%s", testName, logOutput.String()) assert.Equal(t, tc.expectedHTTPStatus, rr.Code) if tc.expectedContentType != "" { - assert.Equal(t, []string{tc.expectedContentType}, rr.HeaderMap["Content-Type"]) + assert.Equal(t, tc.expectedContentType, rr.Result().Header.Get("Content-Type")) } }) } @@ -173,7 +173,7 @@ func TestServeNegotiatingContent(t *testing.T) { t.Logf("testName %q log output:\n%s", testName, logOutput.String()) assert.Equal(t, tc.expectedHTTPStatus, rr.Code) if tc.expectedContentType != "" { - assert.Equal(t, []string{tc.expectedContentType}, rr.HeaderMap["Content-Type"]) + assert.Equal(t, tc.expectedContentType, rr.Result().Header.Get("Content-Type")) } }) } @@ -297,11 +297,9 @@ func TestServeCacheNegotiatingContent(t *testing.T) { func makeRequest(t *testing.T, config *util.Config, headers map[string][]string) *http.Request { req, err := http.NewRequest("GET", config.Endpoint, nil) require.NoError(t, err) - if headers != nil { - for header, vals := range headers { - for _, v := range vals { - req.Header.Add(header, v) - } + for header, vals := range headers { + for _, v := range vals { + req.Header.Add(header, v) } } return req diff --git a/system/file.go b/system/file.go index 6927d910f..a6f1efaef 100644 --- a/system/file.go +++ b/system/file.go @@ -38,14 +38,13 @@ type hashFuncType string const ( md5Hash hashFuncType = "md5" - sha256Hash = "sha256" - sha512Hash = "sha512" + sha256Hash hashFuncType = "sha256" + sha512Hash hashFuncType = "sha512" ) type DefFile struct { path string realPath string - fi os.FileInfo loaded bool err error } @@ -167,7 +166,7 @@ func realPath(path string) (string, error) { if f == "~" { usr, err = user.Current() } else { - usr, err = user.Lookup(f[1:len(f)]) + usr, err = user.Lookup(f[1:]) } if err != nil { return "", err diff --git a/system/kernel_param.go b/system/kernel_param.go index 867e08f65..c7b6e29f8 100644 --- a/system/kernel_param.go +++ b/system/kernel_param.go @@ -14,8 +14,7 @@ type KernelParam interface { } type DefKernelParam struct { - key string - value string + key string } func NewDefKernelParam(_ context.Context, key string, system *System, config util.Config) KernelParam { diff --git a/system/service.go b/system/service.go index df2a43dc7..bdb280702 100644 --- a/system/service.go +++ b/system/service.go @@ -11,8 +11,5 @@ type Service interface { } func invalidService(s string) bool { - if strings.ContainsRune(s, '/') { - return true - } - return false + return strings.ContainsRune(s, '/') } diff --git a/util/config.go b/util/config.go index 8c0a68d19..3be5fa84e 100644 --- a/util/config.go +++ b/util/config.go @@ -271,7 +271,7 @@ func ValidateSections(unmarshal func(any) error, i any, whitelist map[string]boo typ := reflect.TypeOf(i) typs := strings.Split(typ.String(), ".")[1] for id, v := range toValidate { - for k, _ := range v { + for k := range v { if !whitelist[k] { return fmt.Errorf("invalid Attribute for %s:%s: %s", typs, id, k) } @@ -295,7 +295,7 @@ func WhitelistAttrs(i any, format format) (map[string]bool, error) { func IsValueInList(value string, list []string) bool { for _, v := range list { - if strings.ToLower(v) == strings.ToLower(value) { + if strings.EqualFold(v, value) { return true } }