本文整理匯總了Golang中github.com/vmware/photon-controller-go-sdk/photon/internal/mocks.Server.SetResponseJson方法的典型用法代碼示例。如果您正苦於以下問題:Golang Server.SetResponseJson方法的具體用法?Golang Server.SetResponseJson怎麽用?Golang Server.SetResponseJson使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/vmware/photon-controller-go-sdk/photon/internal/mocks.Server
的用法示例。
在下文中一共展示了Server.SetResponseJson方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createTenant
func createTenant(server *mocks.Server, client *Client) string {
mockTask := createMockTask("CREATE_TENANT", "COMPLETED")
server.SetResponseJson(200, mockTask)
tenantSpec := &TenantCreateSpec{Name: randomString(10, "go-sdk-tenant-")}
task, err := client.Tenants.Create(tenantSpec)
GinkgoT().Log(err)
Expect(err).Should(BeNil())
return task.Entity.ID
}
示例2: createResTicket
func createResTicket(server *mocks.Server, client *Client, tenantID string) string {
resTicketName := randomString(10)
spec := &ResourceTicketCreateSpec{
Name: resTicketName,
Limits: []QuotaLineItem{QuotaLineItem{Unit: "GB", Value: 16, Key: "vm.memory"}},
}
mockTask := createMockTask("CREATE_RESOURCE_TICKET", "COMPLETED")
server.SetResponseJson(200, mockTask)
_, err := client.Tenants.CreateResourceTicket(tenantID, spec)
GinkgoT().Log(err)
Expect(err).Should(BeNil())
return resTicketName
}
示例3: createImage
func createImage(server *mocks.Server, client *Client) string {
mockTask := createMockTask("CREATE_IMAGE", "COMPLETED", createMockStep("UPLOAD_IMAGE", "COMPLETED"))
server.SetResponseJson(200, mockTask)
// create image from file
imagePath := "../testdata/tty_tiny.ova"
task, err := client.Images.CreateFromFile(imagePath, &ImageCreateOptions{ReplicationType: "ON_DEMAND"})
task, err = client.Tasks.Wait(task.ID)
GinkgoT().Log(err)
Expect(err).Should(BeNil())
return task.Entity.ID
}
示例4: createFlavor
// Returns flavorName, flavorID
func createFlavor(server *mocks.Server, client *Client) (string, string) {
mockTask := createMockTask("CREATE_FLAVOR", "COMPLETED")
server.SetResponseJson(200, mockTask)
flavorName := randomString(10, "go-sdk-flavor-")
flavorSpec := &FlavorCreateSpec{
[]QuotaLineItem{QuotaLineItem{"COUNT", 1, "persistent-disk.cost"}},
"persistent-disk",
flavorName,
}
task, err := client.Flavors.Create(flavorSpec)
GinkgoT().Log(err)
Expect(err).Should(BeNil())
return flavorName, task.Entity.ID
}
示例5: createProject
func createProject(server *mocks.Server, client *Client, tenantID string, resName string) string {
mockTask := createMockTask("CREATE_PROJECT", "COMPLETED")
server.SetResponseJson(200, mockTask)
projSpec := &ProjectCreateSpec{
ResourceTicket: ResourceTicketReservation{
resName,
[]QuotaLineItem{QuotaLineItem{"GB", 2, "vm.memory"}},
},
Name: randomString(10, "go-sdk-project-"),
}
task, err := client.Tenants.CreateProject(tenantID, projSpec)
GinkgoT().Log(err)
Expect(err).Should(BeNil())
return task.Entity.ID
}
示例6:
SlaveCount: 2,
BatchSize: 1,
ExtendedProperties: mesosMap,
}
})
AfterEach(func() {
cleanClusters(client, projID)
cleanTenants(client)
server.Close()
})
Describe("CreateDeleteCluster", func() {
It("Kubernetes cluster create and delete succeeds", func() {
mockTask := createMockTask("CREATE_CLUSTER", "COMPLETED")
server.SetResponseJson(200, mockTask)
task, err := client.Projects.CreateCluster(projID, kubernetesClusterSpec)
task, err = client.Tasks.Wait(task.ID)
GinkgoT().Log(err)
Expect(err).Should(BeNil())
Expect(task).ShouldNot(BeNil())
Expect(task.Operation).Should(Equal("CREATE_CLUSTER"))
Expect(task.State).Should(Equal("COMPLETED"))
mockTask = createMockTask("DELETE_CLUSTER", "COMPLETED")
server.SetResponseJson(200, mockTask)
task, err = client.Clusters.Delete(task.Entity.ID)
task, err = client.Tasks.Wait(task.ID)
GinkgoT().Log(err)
Expect(err).Should(BeNil())
示例7:
})
ginkgo.AfterEach(func() {
server.Close()
})
ginkgo.Describe("Get", func() {
ginkgo.It("Get deployment info successfully", func() {
baseVersion := "1.1.0"
fullVersion := "1.1.0-bcea65f"
gitCommitHash := "bcea65f"
networkType := "SOFTWARE_DEFINED"
server.SetResponseJson(200,
Info{
BaseVersion: baseVersion,
FullVersion: fullVersion,
GitCommitHash: gitCommitHash,
NetworkType: networkType,
})
info, err := client.Info.Get()
ginkgo.GinkgoT().Log(err)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(info).ShouldNot(gomega.BeNil())
gomega.Expect(info.BaseVersion).Should(gomega.Equal(baseVersion))
gomega.Expect(info.FullVersion).Should(gomega.Equal(fullVersion))
gomega.Expect(info.GitCommitHash).Should(gomega.Equal(gitCommitHash))
gomega.Expect(info.NetworkType).Should(gomega.Equal(networkType))
})
})
示例8:
Skip("Skipping auth test as we don't know if auth is on or off.")
}
server, client = testSetup()
authServer = mocks.NewTlsTestServer()
})
AfterEach(func() {
server.Close()
authServer.Close()
})
Describe("GetAuth", func() {
It("returns auth info", func() {
expected := createMockAuthInfo(nil)
server.SetResponseJson(200, expected)
info, err := client.Auth.Get()
fmt.Fprintf(GinkgoWriter, "Got auth info: %+v\n", info)
Expect(err).Should(BeNil())
Expect(info).Should(BeEquivalentTo(expected))
})
})
Describe("GetTokensByPassword", func() {
Context("when auth is not enabled", func() {
BeforeEach(func() {
server.SetResponseJson(200, createMockAuthInfo(nil))
})
It("returns error", func() {
示例9:
BeforeEach(func() {
server, client = testSetup()
})
AfterEach(func() {
server.Close()
})
It("TaskError", func() {
// Unit test only
if isIntegrationTest() {
return
}
task := &Task{ID: "fake-id", State: "ERROR", Operation: "fake-op"}
server.SetResponseJson(200, task)
task, err := client.Tasks.Wait(task.ID)
taskErr, ok := err.(TaskError)
Expect(ok).ShouldNot(BeNil())
Expect(taskErr.ID).Should(Equal(task.ID))
})
It("TaskTimeoutError", func() {
// Unit test only
if isIntegrationTest() {
return
}
client.options.TaskPollTimeout = 1 * time.Second
task := &Task{ID: "fake-id", State: "QUEUED", Operation: "fake-op"}
server.SetResponseJson(200, task)
task, err := client.Tasks.Wait(task.ID)
示例10:
projID = createProject(server, client, tenantID, resName)
flavorName, flavorID = createFlavor(server, client)
})
AfterEach(func() {
cleanDisks(client, projID)
cleanFlavors(client)
cleanTenants(client)
server.Close()
})
Describe("GetProjectTasks", func() {
It("GetTasks returns a completed task", func() {
mockTask := createMockTask("CREATE_DISK", "COMPLETED")
server.SetResponseJson(200, mockTask)
diskSpec := &DiskCreateSpec{
Flavor: flavorName,
Kind: "persistent-disk",
CapacityGB: 2,
Name: randomString(10, "go-sdk-disk-"),
}
task, err := client.Projects.CreateDisk(projID, diskSpec)
task, err = client.Tasks.Wait(task.ID)
GinkgoT().Log(err)
Expect(err).Should(BeNil())
mockTasksPage := createMockTasksPage(*mockTask)
server.SetResponseJson(200, mockTasksPage)
taskList, err := client.Projects.GetTasks(projID, &TaskGetOptions{})
示例11:
Password: randomString(10),
Address: randomAddress(),
Tags: []string{"CLOUD"},
Metadata: map[string]string{"Test": "go-sdk-host"},
}
})
AfterEach(func() {
cleanHosts(client)
server.Close()
})
Describe("CreateAndDeleteHost", func() {
It("host create and delete succeeds", func() {
mockTask := createMockTask("CREATE_HOST", "COMPLETED")
server.SetResponseJson(200, mockTask)
task, err := client.Hosts.Create(hostSpec, "deployment-Id")
task, err = client.Tasks.Wait(task.ID)
GinkgoT().Log(err)
Expect(err).Should(BeNil())
Expect(task).ShouldNot(BeNil())
Expect(task.Operation).Should(Equal("CREATE_HOST"))
Expect(task.State).Should(Equal("COMPLETED"))
mockTask = createMockTask("DELETE_HOST", "COMPLETED")
server.SetResponseJson(200, mockTask)
task, err = client.Hosts.Delete(task.Entity.ID)
task, err = client.Tasks.Wait(task.ID)
示例12:
flavorSpec = &FlavorCreateSpec{
Name: randomString(10, "go-sdk-flavor-"),
Kind: "vm",
Cost: []QuotaLineItem{QuotaLineItem{"GB", 16, "vm.memory"}},
}
})
AfterEach(func() {
cleanFlavors(client)
server.Close()
})
Describe("CreateGetAndDeleteFlavor", func() {
It("Flavor create and delete succeeds", func() {
mockTask := createMockTask("CREATE_FLAVOR", "COMPLETED")
server.SetResponseJson(200, mockTask)
flavorSpec := &FlavorCreateSpec{
Name: randomString(10, "go-sdk-flavor-"),
Kind: "vm",
Cost: []QuotaLineItem{QuotaLineItem{"GB", 16, "vm.memory"}},
}
task, err := client.Flavors.Create(flavorSpec)
GinkgoT().Log(err)
Expect(err).Should(BeNil())
Expect(task).ShouldNot(BeNil())
Expect(task.Operation).Should(Equal("CREATE_FLAVOR"))
Expect(task.State).Should(Equal("COMPLETED"))
mockTask = createMockTask("DELETE_FLAVOR", "COMPLETED")
示例13:
Name: randomString(10, "go-sdk-vm-"),
}
})
AfterEach(func() {
cleanVMs(client, projID)
cleanImages(client)
cleanFlavors(client)
cleanTenants(client)
server.Close()
})
Describe("CreateAndDeleteVm", func() {
It("Vm create and delete succeeds", func() {
mockTask := createMockTask("CREATE_VM", "COMPLETED")
server.SetResponseJson(200, mockTask)
task, err := client.Projects.CreateVM(projID, vmSpec)
task, err = client.Tasks.Wait(task.ID)
GinkgoT().Log(err)
Expect(err).Should(BeNil())
Expect(task).ShouldNot(BeNil())
Expect(task.Operation).Should(Equal("CREATE_VM"))
Expect(task.State).Should(Equal("COMPLETED"))
mockTask = createMockTask("DELETE_VM", "COMPLETED")
server.SetResponseJson(200, mockTask)
task, err = client.VMs.Delete(task.Entity.ID)
task, err = client.Tasks.Wait(task.ID)
GinkgoT().Log(err)
示例14:
Enabled: false,
},
}
})
AfterEach(func() {
server.Close()
})
Describe("CreateGetAndDeleteDeployment", func() {
It("Deployment create and delete succeeds", func() {
if isIntegrationTest() {
Skip("Skipping deployment test on integration mode. Need undeployed environment")
}
mockTask := createMockTask("CREATE_DEPLOYMENT", "COMPLETED")
server.SetResponseJson(200, mockTask)
task, err := client.Deployments.Create(deploymentSpec)
task, err = client.Tasks.Wait(task.ID)
GinkgoT().Log(err)
Expect(err).Should(BeNil())
Expect(task).ShouldNot(BeNil())
Expect(task.Operation).Should(Equal("CREATE_DEPLOYMENT"))
Expect(task.State).Should(Equal("COMPLETED"))
mockDeployment := Deployment{
ImageDatastores: deploymentSpec.ImageDatastores,
UseImageDatastoreForVms: deploymentSpec.UseImageDatastoreForVms,
Auth: &AuthInfo{Enabled: false},
NetworkConfiguration: &NetworkConfiguration{Enabled: false},
}
示例15:
client *Client
)
BeforeEach(func() {
server, client = testSetup()
})
AfterEach(func() {
cleanTenants(client)
server.Close()
})
Describe("CreateAndDeleteTenant", func() {
It("Tenant create and delete succeeds", func() {
mockTask := createMockTask("CREATE_TENANT", "COMPLETED")
server.SetResponseJson(200, mockTask)
tenantSpec := &TenantCreateSpec{Name: randomString(10, "go-sdk-tenant-")}
task, err := client.Tenants.Create(tenantSpec)
task, err = client.Tasks.Wait(task.ID)
GinkgoT().Log(err)
Expect(err).Should(BeNil())
Expect(task).ShouldNot(BeNil())
Expect(task.Operation).Should(Equal("CREATE_TENANT"))
Expect(task.State).Should(Equal("COMPLETED"))
mockTask = createMockTask("DELETE_TENANT", "COMPLETED")
server.SetResponseJson(200, mockTask)
task, err = client.Tenants.Delete(task.Entity.ID)
GinkgoT().Log(err)