goss-org / goss

Quick and Easy server testing/validation
https://goss.rocks
Apache License 2.0
5.5k stars 470 forks source link

Goss crashes when json or junit output is used with io.Readers #848

Closed pahaeanx closed 8 months ago

pahaeanx commented 8 months ago

Describe the bug When using advanced matching using io.Readers, goss validate panics when the json or junit output is used.

How To Reproduce

# file goss.yaml
command:
  testing:
    exec: printf "oneline\nsecondline\nthirdline"
    exit-status: 0
    stdout:
      and:
        - contain-element: "oneline"
        - contain-element: "thirdline

Then run

$ for type in documentation json junit nagios prometheus rspecish silent structured tap; do echo ${type}; goss validate -f ${type} >/dev/null;  done

to validate the above tests with each available output format.

Expected Behavior No crash on these two output formats.

Actual Behavior Test crashes on the json and junit outputs:

root@moep:~# for type in documentation json junit nagios prometheus rspecish silent structured tap; do echo ${type}; goss validate -f ${type} >/dev/null;  done
documentation
json
panic: interface conversion: interface {} is nil, not float64

goroutine 1 [running]:
github.com/goss-org/goss/outputs.Json.Output({}, {0xc86920, 0xc00012e008}, 0xc0002e8240?, {{0x11ba608?, 0xc000289880?, 0xc0002b3280?}})
        /home/travis/gopath/src/github.com/goss-org/goss/outputs/json.go:62 +0x104a
github.com/goss-org/goss.ValidateConfig(0xc00031e200, 0xc0002b2f00)
        /home/travis/gopath/src/github.com/goss-org/goss/validate.go:142 +0x42a
github.com/goss-org/goss.Validate(0xc00031e200)
        /home/travis/gopath/src/github.com/goss-org/goss/validate.go:111 +0x85
main.main.func1(0xc00029e6e0?)
        /home/travis/gopath/src/github.com/goss-org/goss/cmd/goss/goss.go:151 +0x25
github.com/urfave/cli.HandleAction({0xaaa1a0?, 0xbddc50?}, 0x8?)
        /home/travis/gopath/pkg/mod/github.com/urfave/cli@v1.22.14/app.go:524 +0x50
github.com/urfave/cli.Command.Run({{0xb8f1c5, 0x8}, {0x0, 0x0}, {0xc000376360, 0x1, 0x1}, {0xb95bee, 0xf}, {0x0, ...}, ...}, ...)
        /home/travis/gopath/pkg/mod/github.com/urfave/cli@v1.22.14/command.go:175 +0x67b
github.com/urfave/cli.(*App).Run(0xc0002be1c0, {0xc000132040, 0x4, 0x4})
        /home/travis/gopath/pkg/mod/github.com/urfave/cli@v1.22.14/app.go:277 +0xb87
main.main()
        /home/travis/gopath/src/github.com/goss-org/goss/cmd/goss/goss.go:408 +0x2078
junit
panic: interface conversion: interface {} is nil, not float64

goroutine 1 [running]:
github.com/goss-org/goss/outputs.JUnit.Output({}, {0xc86920, 0xc000012018}, 0xc00028e240?, {{0x11ba608?, 0xc0000c98d0?, 0xc0000cb300?}})
        /home/travis/gopath/src/github.com/goss-org/goss/outputs/junit.go:51 +0xe8c
github.com/goss-org/goss.ValidateConfig(0xc0002c2200, 0xc0000caf80)
        /home/travis/gopath/src/github.com/goss-org/goss/validate.go:142 +0x42a
github.com/goss-org/goss.Validate(0xc0002c2200)
        /home/travis/gopath/src/github.com/goss-org/goss/validate.go:111 +0x85
main.main.func1(0xc0000d26e0?)
        /home/travis/gopath/src/github.com/goss-org/goss/cmd/goss/goss.go:151 +0x25
github.com/urfave/cli.HandleAction({0xaaa1a0?, 0xbddc50?}, 0x8?)
        /home/travis/gopath/pkg/mod/github.com/urfave/cli@v1.22.14/app.go:524 +0x50
github.com/urfave/cli.Command.Run({{0xb8f1c5, 0x8}, {0x0, 0x0}, {0xc0002f8630, 0x1, 0x1}, {0xb95bee, 0xf}, {0x0, ...}, ...}, ...)
        /home/travis/gopath/pkg/mod/github.com/urfave/cli@v1.22.14/command.go:175 +0x67b
github.com/urfave/cli.(*App).Run(0xc0000e21c0, {0xc0000340c0, 0x4, 0x4})
        /home/travis/gopath/pkg/mod/github.com/urfave/cli@v1.22.14/app.go:277 +0xb87
main.main()
        /home/travis/gopath/src/github.com/goss-org/goss/cmd/goss/goss.go:408 +0x2078
nagios
prometheus
rspecish
silent
structured
tap

I have not tested other matchers/negations or regex but I expect the would also crash.

Environment:

pahaeanx commented 8 months ago

Sorry, just noticed this is a duplicated of #846 The only new thing I can contribute is the crash on json output. Feel free to close this.

Closing this.