goss-org / goss

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

Error with `contain-substring/mach-regexp` matcher and `json/junit` formatters #846

Closed loliee closed 8 months ago

loliee commented 9 months ago

Describe the bug

I try to use the contain-substring matcher with the junit, json formatters but I have the following error: panic: interface conversion: interface {} is nil, not float64.

How To Reproduce

# goss/datadog.yml
package:
  datadog-agent:
     installed: true
     versions:
       and:
         - have-len: 1
         - contain-substring: "7.1"

And validate it with junit formatter :

goss -g goss/datadog.yml validate -f junit

ℹ️ I also had the same issues with ip ressource.

Expected Behavior

Finishing without errors like with the documentation or rspecish formatters.

Actual Behavior

goss -g goss/datadog.yml validate -f documentation
Package: datadog-agent: installed: matches expectation: true
Package: datadog-agent: version: matches expectation: {"and":[{"have-len":1},{"contain-substring":"7.1"}]}

💥

goss -g goss/datadog.yml validate -f junit
panic: interface conversion: interface {} is nil, not float64

goroutine 1 [running]:
github.com/goss-org/goss/outputs.JUnit.Output({}, {0xc86920, 0xc000012018}, 0xc0000463c0?, {{0x11ba608?, 0xc0001c0a40?, 0xc000282400?}})
        /home/travis/gopath/src/github.com/goss-org/goss/outputs/junit.go:51 +0xe8c
github.com/goss-org/goss.ValidateConfig(0xc0001c6200, 0xc000282280)
        /home/travis/gopath/src/github.com/goss-org/goss/validate.go:142 +0x42a
github.com/goss-org/goss.Validate(0xc0001c6200)
        /home/travis/gopath/src/github.com/goss-org/goss/validate.go:111 +0x85
main.main.func1(0xc00010b1e0?)
        /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}, {0xc000191b20, 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(0xc000164e00, {0xc0000341e0, 0x6, 0x6})
        /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

Environment:

loliee commented 9 months ago

I also tried with mach-regexp with same kind of issue:

package:
  datadog-agent:
    installed: true
    versions:
      and:
        - have-len: 1
        - match-regexp: '^1:7\.\d+\.\d+(-\d+)?'
goss -g goss/datadog.yml validate -f documentation
Package: datadog-agent: installed: matches expectation: true
Package: datadog-agent: version: matches expectation: {"and":[{"have-len":1},{"match-regexp":"^1:7\\.\\d+\\.\\d+(-\\d+)?"}]}

Total Duration: 0.020s
Count: 5, Failed: 0, Skipped: 0
goss -g goss/datadog.yml validate -f junit
panic: interface conversion: interface {} is nil, not float64

goroutine 1 [running]:
github.com/goss-org/goss/outputs.JUnit.Output({}, {0xc86920, 0xc000012018}, 0xc00026a300?, {{0x11ba608?, 0xc0003105e0?, 0xc000237180?}})
        /home/travis/gopath/src/github.com/goss-org/goss/outputs/junit.go:51 +0xe8c
github.com/goss-org/goss.ValidateConfig(0xc0002a0200, 0xc000236f00)
        /home/travis/gopath/src/github.com/goss-org/goss/validate.go:142 +0x42a
github.com/goss-org/goss.Validate(0xc0002a0200)
        /home/travis/gopath/src/github.com/goss-org/goss/validate.go:111 +0x85
main.main.func1(0xc0002226e0?)
        /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}, {0xc0002f63b0, 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(0xc0002421c0, {0xc000034080, 0x8, 0x8})
        /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
aelsabbahy commented 8 months ago

Thank you for filing this, I've been able to reproduce locally. My plan is to have this fixed sometime this week.