1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
package e2e_test
import (
"context"
"os/exec"
"path/filepath"
"runtime"
"github.com/containers/podman/v5/pkg/machine"
"github.com/docker/docker/client"
jsoniter "github.com/json-iterator/go"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)
const (
NamedPipeProto = "npipe://"
)
var _ = Describe("run podman API test calls", func() {
It("client connect to machine socket", func() {
if runtime.GOOS == "windows" {
Skip("Go docker client doesn't support unix socket on Windows")
}
name := randomString()
i := new(initMachine)
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withNow()).run()
Expect(err).ToNot(HaveOccurred())
Expect(session).To(Exit(0))
inspectJSON := new(inspectMachine)
inspectSession, err := mb.setName(name).setCmd(inspectJSON).run()
Expect(err).ToNot(HaveOccurred())
Expect(inspectSession).To(Exit(0))
var inspectInfo []machine.InspectInfo
err = jsoniter.Unmarshal(inspectSession.Bytes(), &inspectInfo)
Expect(err).ToNot(HaveOccurred())
sockPath := inspectInfo[0].ConnectionInfo.PodmanSocket.GetPath()
cli, err := client.NewClientWithOpts(client.WithHost("unix://" + sockPath))
Expect(err).ToNot(HaveOccurred())
_, err = cli.Ping(context.Background())
Expect(err).ToNot(HaveOccurred())
})
It("client connect to machine named pipe", func() {
if runtime.GOOS != "windows" {
Skip("test is only supported on Windows")
}
name := randomString()
i := new(initMachine)
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withNow()).run()
Expect(err).ToNot(HaveOccurred())
Expect(session).To(Exit(0))
inspectJSON := new(inspectMachine)
inspectSession, err := mb.setName(name).setCmd(inspectJSON).run()
Expect(err).ToNot(HaveOccurred())
Expect(inspectSession).To(Exit(0))
var inspectInfo []machine.InspectInfo
err = jsoniter.Unmarshal(inspectSession.Bytes(), &inspectInfo)
Expect(err).ToNot(HaveOccurred())
pipePath := inspectInfo[0].ConnectionInfo.PodmanPipe.GetPath()
cli, err := client.NewClientWithOpts(client.WithHost(NamedPipeProto + filepath.ToSlash(pipePath)))
Expect(err).ToNot(HaveOccurred())
_, err = cli.Ping(context.Background())
Expect(err).ToNot(HaveOccurred())
})
It("curl connect to machine socket", func() {
name := randomString()
i := new(initMachine)
session, err := mb.setName(name).setCmd(i.withImage(mb.imagePath).withNow()).run()
Expect(err).ToNot(HaveOccurred())
Expect(session).To(Exit(0))
inspectJSON := new(inspectMachine)
inspectSession, err := mb.setName(name).setCmd(inspectJSON).run()
Expect(err).ToNot(HaveOccurred())
Expect(inspectSession).To(Exit(0))
var inspectInfo []machine.InspectInfo
err = jsoniter.Unmarshal(inspectSession.Bytes(), &inspectInfo)
Expect(err).ToNot(HaveOccurred())
sockPath := inspectInfo[0].ConnectionInfo.PodmanSocket.GetPath()
cmd := exec.Command("curl", "--unix-socket", sockPath, "http://d/v5.0.0/libpod/info")
err = cmd.Run()
Expect(err).ToNot(HaveOccurred())
})
})
|