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
}
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
}
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
}
// 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
}
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
}
			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())
	})

	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))
		})
	})
			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() {
	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)
		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{})
			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)
		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")
			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)
				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},
			}
		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)
			Description:          "a test virtual network",
			RoutingType:          "ROUTED",
			Size:                 256,
			ReservedStaticIpSize: 20,
		}
	})

	ginkgo.AfterEach(func() {
		cleanVirtualSubnets(client, projectId)
		server.Close()
	})

	ginkgo.Describe("CreateDeleteVirtualSubnet", func() {
		ginkgo.It("Virtual subnet create and delete succeeds", func() {
			mockTask := createMockTask("CREATE_VIRTUAL_NETWORK", "COMPLETED")
			server.SetResponseJson(200, mockTask)

			task, err := client.VirtualSubnets.Create(projectId, networkSpec)
			task, err = client.Tasks.Wait(task.ID)
			ginkgo.GinkgoT().Log(err)

			gomega.Expect(err).Should(gomega.BeNil())
			gomega.Expect(task).ShouldNot(gomega.BeNil())
			gomega.Expect(task.Operation).Should(gomega.Equal("CREATE_VIRTUAL_NETWORK"))
			gomega.Expect(task.State).Should(gomega.Equal("COMPLETED"))

			mockTask = createMockTask("DELETE_VIRTUAL_NETWORK", "COMPLETED")
			server.SetResponseJson(200, mockTask)
			ginkgo.GinkgoT().Log(err)

			task, err = client.VirtualSubnets.Delete(task.Entity.ID)
	BeforeEach(func() {
		server, client = testSetup()
		tenantID = createTenant(server, client)
	})

	AfterEach(func() {
		cleanTenants(client)
		server.Close()
	})

	Describe("GetResourceTicketTasks", func() {
		It("GetTasks returns a completed task", func() {
			mockTask := createMockTask("CREATE_RESOURCE_TICKET", "COMPLETED")
			mockTask.Entity.ID = "mock-task-id"
			server.SetResponseJson(200, mockTask)
			spec := &ResourceTicketCreateSpec{
				Name:   randomString(10),
				Limits: []QuotaLineItem{QuotaLineItem{Unit: "GB", Value: 16, Key: "vm.memory"}},
			}
			task, err := client.Tenants.CreateResourceTicket(tenantID, spec)

			GinkgoT().Log(err)
			Expect(err).Should(BeNil())
			Expect(task).ShouldNot(BeNil())
			Expect(task.Operation).Should(Equal("CREATE_RESOURCE_TICKET"))
			Expect(task.State).Should(Equal("COMPLETED"))

			mockTasksPage := createMockTasksPage(*mockTask)
			server.SetResponseJson(200, mockTasksPage)
			taskList, err := client.ResourceTickets.GetTasks(task.Entity.ID, &TaskGetOptions{})
		client *Client
	)

	BeforeEach(func() {
		server, client = testSetup()
	})

	AfterEach(func() {
		cleanImages(client)
		server.Close()
	})

	Describe("CreateAndDeleteImage", func() {
		It("Image create from file and delete succeeds", func() {
			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())
			Expect(task).ShouldNot(BeNil())
			Expect(task.Operation).Should(Equal("CREATE_IMAGE"))
			Expect(task.State).Should(Equal("COMPLETED"))

			mockTask = createMockTask("DELETE_IMAGE", "COMPLETED")
			server.SetResponseJson(200, mockTask)
			task, err = client.Images.Delete(task.Entity.ID)
				It("returns an error", func() {
					certList, err := client.GetRootCerts()
					Expect(certList).To(BeNil())
					Expect(err).ToNot(BeNil())
					Expect(err).To(MatchError("invalid character 'e' in literal true (expecting 'r')"))
				})
			})

			Context("when server responds with unparasble cert data", func() {
				BeforeEach(func() {
					body := []lightWaveCert{
						lightWaveCert{Value: "text"},
					}

					server.SetResponseJson(200, body)
				})

				It("returns an error", func() {
					certList, err := client.GetRootCerts()
					Expect(certList).To(BeNil())
					Expect(err).ToNot(BeNil())
					Expect(err).To(MatchError("Unexpected response format: &[{text}]"))
				})
			})

			Context("when server responds with error", func() {
				BeforeEach(func() {
					server.SetResponseForPath(certDownloadPath, 400, "")
				})
		server *mocks.Server
		client *Client
	)

	BeforeEach(func() {
		server, client = testSetup()
	})

	AfterEach(func() {
		server.Close()
	})

	Describe("CreateAndDeleteAvailabilityZone", func() {
		It("AvailabilityZone create and delete succeeds", func() {
			mockTask := createMockTask("CREATE_AVAILABILITYZONE", "COMPLETED")
			server.SetResponseJson(200, mockTask)
			availabilityzoneSpec := &AvailabilityZoneCreateSpec{Name: randomString(10, "go-sdk-availabilityzone-")}
			task, err := client.AvailabilityZones.Create(availabilityzoneSpec)
			task, err = client.Tasks.Wait(task.ID)

			GinkgoT().Log(err)
			Expect(err).Should(BeNil())
			Expect(task).ShouldNot(BeNil())
			Expect(task.Operation).Should(Equal("CREATE_AVAILABILITYZONE"))
			Expect(task.State).Should(Equal("COMPLETED"))

			mockTask = createMockTask("DELETE_AVAILABILITYZONE", "COMPLETED")
			server.SetResponseJson(200, mockTask)
			task, err = client.AvailabilityZones.Delete(task.Entity.ID)

			GinkgoT().Log(err)
			CapacityGB: 2,
			Name:       randomString(10, "go-sdk-disk-"),
		}
	})

	AfterEach(func() {
		cleanDisks(client, projID)
		cleanFlavors(client)
		cleanTenants(client)
		server.Close()
	})

	Describe("CreateAndDeleteDisk", func() {
		It("Disk create and delete succeeds", func() {
			mockTask := createMockTask("CREATE_DISK", "COMPLETED")
			server.SetResponseJson(200, mockTask)

			task, err := client.Projects.CreateDisk(projID, diskSpec)
			task, err = client.Tasks.Wait(task.ID)
			GinkgoT().Log(err)
			Expect(err).Should(BeNil())
			Expect(task).ShouldNot(BeNil())
			Expect(task.Operation).Should(Equal("CREATE_DISK"))
			Expect(task.State).Should(Equal("COMPLETED"))

			mockTask = createMockTask("DELETE_DISK", "COMPLETED")
			server.SetResponseJson(200, mockTask)
			task, err = client.Disks.Delete(task.Entity.ID)
			task, err = client.Tasks.Wait(task.ID)

			GinkgoT().Log(err)
	. "github.com/onsi/gomega"
	"github.com/vmware/photon-controller-go-sdk/photon/internal/mocks"
)

var _ = Describe("Status", func() {
	var (
		server *mocks.Server
		client *Client
	)

	BeforeEach(func() {
		server, client = testSetup()
	})

	AfterEach(func() {
		server.Close()
	})

	// Simple preliminary test. Make sure status API correctly deserializes the response
	It("GetStatus200", func() {
		expectedStruct := Status{"READY", []Component{{"chairman", "", "READY"}, {"housekeeper", "", "READY"}}}
		server.SetResponseJson(200, expectedStruct)

		status, err := client.Status.Get()
		GinkgoT().Log(err)
		Expect(err).Should(BeNil())
		Expect(status.Status).Should(Equal(expectedStruct.Status))
		Expect(status.Components).ShouldNot(HaveLen(1))
	})
})