github.com/containers/podman/v4@v4.9.4/pkg/machine/e2e/info_test.go (about)

     1  package e2e_test
     2  
     3  import (
     4  	"strconv"
     5  
     6  	"github.com/containers/podman/v4/pkg/domain/entities"
     7  	jsoniter "github.com/json-iterator/go"
     8  	. "github.com/onsi/ginkgo/v2"
     9  	. "github.com/onsi/gomega"
    10  	. "github.com/onsi/gomega/gexec"
    11  )
    12  
    13  var _ = Describe("podman machine info", func() {
    14  	var (
    15  		mb      *machineTestBuilder
    16  		testDir string
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		testDir, mb = setup()
    21  	})
    22  	AfterEach(func() {
    23  		teardown(originalHomeDir, testDir, mb)
    24  	})
    25  
    26  	It("machine info", func() {
    27  		info := new(infoMachine)
    28  		infoSession, err := mb.setCmd(info).run()
    29  		Expect(err).NotTo(HaveOccurred())
    30  		Expect(infoSession).Should(Exit(0))
    31  
    32  		// Verify go template works and check for number of machines
    33  		info = new(infoMachine)
    34  		infoSession, err = mb.setCmd(info.withFormat("{{.Host.NumberOfMachines}}")).run()
    35  		Expect(err).NotTo(HaveOccurred())
    36  		Expect(infoSession).Should(Exit(0))
    37  		numMachines, err := strconv.Atoi(infoSession.outputToString())
    38  		Expect(err).ToNot(HaveOccurred())
    39  
    40  		// Create a machine and check if info has been updated
    41  		i := new(initMachine)
    42  		initSession, err := mb.setCmd(i.withImagePath(mb.imagePath)).run()
    43  		Expect(err).ToNot(HaveOccurred())
    44  		Expect(initSession).To(Exit(0))
    45  
    46  		info = new(infoMachine)
    47  		infoSession, err = mb.setCmd(info.withFormat("{{.Host.NumberOfMachines}}")).run()
    48  		Expect(err).NotTo(HaveOccurred())
    49  		Expect(infoSession).Should(Exit(0))
    50  		Expect(infoSession.outputToString()).To(Equal(strconv.Itoa(numMachines + 1)))
    51  
    52  		// Check if json is in correct format
    53  		infoSession, err = mb.setCmd(info.withFormat("json")).run()
    54  		Expect(err).NotTo(HaveOccurred())
    55  		Expect(infoSession).Should(Exit(0))
    56  
    57  		infoReport := &entities.MachineInfo{}
    58  		err = jsoniter.Unmarshal(infoSession.Bytes(), infoReport)
    59  		Expect(err).ToNot(HaveOccurred())
    60  	})
    61  })