本文整理匯總了Golang中github.com/cloudfoundry-incubator/garden.Client.Create方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Create方法的具體用法?Golang Client.Create怎麽用?Golang Client.Create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry-incubator/garden.Client
的用法示例。
在下文中一共展示了Client.Create方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createContainer
func createContainer(gardenClient garden.Client) (string, error) {
container, err := gardenClient.Create(garden.ContainerSpec{})
if err != nil {
return "", err
}
processSpec := garden.ProcessSpec{
Path: "sleep",
Args: []string{"1000000"},
User: "root",
}
processIO := garden.ProcessIO{}
_, err = container.Run(processSpec, processIO)
if err != nil {
panic(err)
}
handle := container.Handle()
fmt.Println(handle)
return handle, nil
}
示例2: createContainer
func createContainer(client garden.Client, spec garden.ContainerSpec) garden.Container {
container, err := client.Create(spec)
Ω(err).ShouldNot(HaveOccurred(), fmt.Sprintf("Error while creating container with spec: %+v", spec))
return container
}
示例3:
})
})
Context("and the client sends a CreateRequest", func() {
var fakeContainer *fakes.FakeContainer
BeforeEach(func() {
fakeContainer = new(fakes.FakeContainer)
fakeContainer.HandleReturns("some-handle")
serverBackend.CreateReturns(fakeContainer, nil)
})
It("returns a container with the created handle", func() {
container, err := apiClient.Create(garden.ContainerSpec{
Handle: "some-handle",
})
Ω(err).ShouldNot(HaveOccurred())
Ω(container.Handle()).Should(Equal("some-handle"))
})
It("creates the container with the spec from the request", func() {
_, err := apiClient.Create(garden.ContainerSpec{
Handle: "some-handle",
GraceTime: 42 * time.Second,
Network: "some-network",
RootFSPath: "/path/to/rootfs",
BindMounts: []garden.BindMount{
{
SrcPath: "/bind/mount/src",
示例4:
finishCreating = make(chan struct{})
fakeBackend.CreateStub = func(garden.ContainerSpec) (garden.Container, error) {
close(creating)
<-finishCreating
return new(fakes.FakeContainer), nil
}
})
It("waits for it to complete and stops accepting requests", func() {
created := make(chan garden.Container, 1)
go func() {
defer GinkgoRecover()
container, err := apiClient.Create(garden.ContainerSpec{})
Ω(err).ShouldNot(HaveOccurred())
created <- container
}()
Eventually(creating).Should(BeClosed())
stopExited := make(chan struct{})
go func() {
apiServer.Stop()
close(stopExited)
}()
Consistently(stopExited).ShouldNot(BeClosed())