mirror of
https://github.com/containers/podman.git
synced 2025-06-24 03:08:13 +08:00
Merge pull request #19669 from ashley-cui/testlist
Update machine list test
This commit is contained in:
@ -14,7 +14,9 @@ import (
|
|||||||
"github.com/containers/storage/pkg/stringid"
|
"github.com/containers/storage/pkg/stringid"
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/onsi/gomega/format"
|
||||||
. "github.com/onsi/gomega/gexec"
|
. "github.com/onsi/gomega/gexec"
|
||||||
|
"github.com/onsi/gomega/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var originalHomeDir = os.Getenv("HOME")
|
var originalHomeDir = os.Getenv("HOME")
|
||||||
@ -170,3 +172,32 @@ func runWrapper(podmanBinary string, cmdArgs []string, timeout time.Duration, wa
|
|||||||
func randomString() string {
|
func randomString() string {
|
||||||
return stringid.GenerateRandomID()[0:12]
|
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")
|
||||||
|
}
|
||||||
|
@ -133,6 +133,7 @@ var _ = Describe("podman machine list", func() {
|
|||||||
listSession2, err := mb.setCmd(list2).run()
|
listSession2, err := mb.setCmd(list2).run()
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(listSession2).To(Exit(0))
|
Expect(listSession2).To(Exit(0))
|
||||||
|
Expect(listSession2.outputToString()).To(BeValidJSON())
|
||||||
|
|
||||||
var listResponse []*entities.ListReporter
|
var listResponse []*entities.ListReporter
|
||||||
err = jsoniter.Unmarshal(listSession2.Bytes(), &listResponse)
|
err = jsoniter.Unmarshal(listSession2.Bytes(), &listResponse)
|
||||||
|
Reference in New Issue
Block a user