Skip to content

Commit

Permalink
Merge branch 'goss-org:master' into codeclimate_golint
Browse files Browse the repository at this point in the history
  • Loading branch information
dklimpel authored Jun 8, 2024
2 parents 478c79b + 6a8fc96 commit 7ad74c5
Show file tree
Hide file tree
Showing 39 changed files with 109 additions and 138 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
only-new-issues: true
version: v1.59
16 changes: 16 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
golangci-lint run --timeout 5m $(pkgs) || true

vet:
$(info INFO: Starting build $@)
Expand Down
8 changes: 0 additions & 8 deletions cmd/goss/goss.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/Dockerfile_alpine3
Original file line number Diff line number Diff line change
@@ -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/*
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/goss/alpine3/goss-aa-expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package:
apache2:
installed: true
versions:
- 2.4.46-r1
- 2.4.59-r0
service:
apache2:
enabled: true
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/goss/alpine3/goss-expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ package:
apache2:
installed: true
versions:
- 2.4.46-r1
- 2.4.59-r0
foobar:
installed: false
vim-tiny:
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/goss/vars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 0 additions & 8 deletions matchers/have_patterns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions matchers/type_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"strconv"
"strings"

Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions outputs/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions outputs/junit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions outputs/nagios.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions outputs/rspecish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
}
Expand Down
3 changes: 1 addition & 2 deletions outputs/tap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion resource/addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type Addr struct {
Skip bool `json:"skip,omitempty" yaml:"skip,omitempty"`
}

type idKey struct{}

const (
AddrResourceKey = "addr"
AddResourceName = "Addr"
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion resource/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion resource/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion resource/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})

Expand Down
2 changes: 1 addition & 1 deletion resource/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})

Expand Down
2 changes: 1 addition & 1 deletion resource/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion resource/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})

Expand Down
2 changes: 1 addition & 1 deletion resource/kernel_param.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})

Expand Down
2 changes: 1 addition & 1 deletion resource/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion resource/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})

Expand Down
2 changes: 1 addition & 1 deletion resource/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})

Expand Down
2 changes: 1 addition & 1 deletion resource/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})

Expand Down
14 changes: 0 additions & 14 deletions resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import (
"os"
"path/filepath"
"strconv"
"strings"
"sync"

"github.com/goss-org/goss/system"
"github.com/oleiade/reflections"
)

type Resource interface {
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 7ad74c5

Please sign in to comment.