Merge pull request #19669 from ashley-cui/testlist

Update machine list test
This commit is contained in:
OpenShift Merge Robot
2023-08-18 06:35:22 -02:30
committed by GitHub
2 changed files with 32 additions and 0 deletions

View File

@ -14,7 +14,9 @@ import (
"github.com/containers/storage/pkg/stringid"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/format"
. "github.com/onsi/gomega/gexec"
"github.com/onsi/gomega/types"
)
var originalHomeDir = os.Getenv("HOME")
@ -170,3 +172,32 @@ func runWrapper(podmanBinary string, cmdArgs []string, timeout time.Duration, wa
func randomString() string {
return stringid.GenerateRandomID()[0:12]
}
type ValidJSONMatcher struct {
types.GomegaMatcher
}
func BeValidJSON() *ValidJSONMatcher {
return &ValidJSONMatcher{}
}
func (matcher *ValidJSONMatcher) Match(actual interface{}) (success bool, err error) {
s, ok := actual.(string)
if !ok {
return false, fmt.Errorf("ValidJSONMatcher expects a string, not %q", actual)
}
var i interface{}
if err := json.Unmarshal([]byte(s), &i); err != nil {
return false, err
}
return true, nil
}
func (matcher *ValidJSONMatcher) FailureMessage(actual interface{}) (message string) {
return format.Message(actual, "to be valid JSON")
}
func (matcher *ValidJSONMatcher) NegatedFailureMessage(actual interface{}) (message string) {
return format.Message(actual, "to _not_ be valid JSON")
}

View File

@ -133,6 +133,7 @@ var _ = Describe("podman machine list", func() {
listSession2, err := mb.setCmd(list2).run()
Expect(err).ToNot(HaveOccurred())
Expect(listSession2).To(Exit(0))
Expect(listSession2.outputToString()).To(BeValidJSON())
var listResponse []*entities.ListReporter
err = jsoniter.Unmarshal(listSession2.Bytes(), &listResponse)