func TestGetFlavorDetail(t *testing.T) {
	flavorID := "101"
	mockResponseObject := FlavorDetailContainer{FlavorDetail: sampleFlavorDetail}
	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObject(t, tokn, mockResponseObject, misc.Strcat("/flavors/", flavorID))
	defer apiServer.Close()

	service := CreateComputeService(apiServer.URL)
	result, err := service.FlavorDetail(flavorID)
	testUtil.IsNil(t, err)

	testUtil.Equals(t, sampleFlavorDetail, result)
}
func TestGetServerMetaItem(t *testing.T) {
	sampleMetadata := map[string]string{"status": "OK"}

	mockResponseObject := serverMetaItemContainer{Meta: sampleMetadata}
	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObject(t, tokn, mockResponseObject, "servers/"+testServeID+"/metadata/status")
	defer apiServer.Close()

	service := CreateComputeService(apiServer.URL)
	foundItem, err := service.ServerMetadataItem(testServeID, "status")
	testUtil.IsNil(t, err)
	testUtil.Equals(t, "OK", foundItem)
}
func TestGetPort(t *testing.T) {
	mockResponseObject := portContainer{Port: samplePortResponse}
	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObject(t, tokn, mockResponseObject, "/ports/23507256")
	defer apiServer.Close()

	networkService := CreateNetworkService(apiServer.URL)
	port, err := networkService.Port("23507256")
	if err != nil {
		t.Error(err)
	}
	testUtil.Equals(t, samplePortResponse, port)
}
func TestGetNetwork(t *testing.T) {
	mockResponseObject := networkContainer{Network: sampleNetworkResponse}
	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObject(t, tokn, mockResponseObject, "/networks/5270u2tg0")
	defer apiServer.Close()

	networkService := CreateNetworkService(apiServer.URL)
	network, err := networkService.Network("5270u2tg0")
	if err != nil {
		t.Error(err)
	}

	testUtil.Equals(t, sampleNetworkResponse, network)
}
func TestGetNetworkIDsByName(t *testing.T) {
	mockResponseObject := networksContainer{Networks: []network.Response{sampleNetworkResponse}}
	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObject(t, tokn, mockResponseObject, "/networks?fields=id&name=networkName")
	defer apiServer.Close()

	networkService := CreateNetworkService(apiServer.URL)
	networkIDs, err := networkService.NetworkIDsByName(sampleNetworkResponse.Name)
	if err != nil {
		t.Error(err)
	}

	testUtil.Equals(t, []string{sampleNetworkResponse.ID}, networkIDs)
}
func TestGetFloatingIP(t *testing.T) {
	mockResponseObject := floatingIPContainer{FloatingIP: samplefloatingIP}
	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObject(t, tokn, mockResponseObject, "os-floating-ips/id")
	defer apiServer.Close()

	service := CreateComputeService(apiServer.URL)
	keypair, err := service.FloatingIP("id")
	if err != nil {
		t.Error(err)
	}

	testUtil.Equals(t, samplefloatingIP, keypair)
}
func TestGetSubnet(t *testing.T) {
	mockResponseObject := subnetResp{Subnet: sampleSubNetResponse}
	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObject(t, tokn, mockResponseObject, "/subnets/5270u2tg0")
	defer apiServer.Close()

	networkService := CreateNetworkService(apiServer.URL)
	subnet, err := networkService.Subnet("5270u2tg0")
	if err != nil {
		t.Error(err)
	}

	testUtil.Equals(t, sampleSubNetResponse, subnet)
}
func TestGetServerMetadata(t *testing.T) {
	sampleMetadata := map[string]string{
		"status":  "OK",
		"message": "Processing is working!"}

	mockResponseObject := serverMetadataContainer{Metadata: sampleMetadata}
	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObject(t, tokn, mockResponseObject, "servers/"+testServeID+"/metadata")
	defer apiServer.Close()

	service := CreateComputeService(apiServer.URL)
	foundMetadata, err := service.ServerMetadata(testServeID)
	testUtil.IsNil(t, err)
	testUtil.Equals(t, sampleMetadata, foundMetadata)
}
func TestGetVolumeAttachment(t *testing.T) {

	mockResponseObject := volumeAttachmentContainer{VolumeAttachment: sampleVolumeAttachment}
	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObject(t, tokn, mockResponseObject, "/servers/serverID/os-volume_attachments/id")
	defer apiServer.Close()

	service := CreateComputeService(apiServer.URL)

	attachedVolume, err := service.VolumeAttachment("serverID", "id")
	if err != nil {
		t.Fatal(err)
	}

	testUtil.Equals(t, sampleVolumeAttachment, attachedVolume)
}
func TestGetNetworks(t *testing.T) {
	mockResponseObject := networksContainer{Networks: []network.Response{sampleNetworkResponse}}
	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObject(t, tokn, mockResponseObject, "/networks")
	defer apiServer.Close()

	networkService := CreateNetworkService(apiServer.URL)
	networks, err := networkService.Networks()
	if err != nil {
		t.Error(err)
	}

	if len(networks) != 1 {
		t.Error(errors.New("Error: Expected 2 networks to be listed"))
	}
	testUtil.Equals(t, sampleNetworkResponse, networks[0])
}
func TestGetFloatingIPs(t *testing.T) {
	mockResponseObject := floatingIPsContainer{FloatingIPs: []compute.FloatingIP{samplefloatingIP}}
	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObject(t, tokn, mockResponseObject, "os-floating-ips")
	defer apiServer.Close()

	service := CreateComputeService(apiServer.URL)
	floatingIPs, err := service.FloatingIPs()
	if err != nil {
		t.Error(err)
	}

	if len(floatingIPs) != 1 {
		t.Error(errors.New("Error: Expected 1 floating ip to be listed"))
	}
	testUtil.Equals(t, samplefloatingIP, floatingIPs[0])
}
func TestGetFlavorsDetail(t *testing.T) {
	mockResponseObject := FlavorsDetailContainer{
		FlavorsDetail: []FlavorDetail{sampleFlavorDetail, sampleFlavorDetail2}}
	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObject(t, tokn, mockResponseObject, "/flavors/detail?limit=21")
	defer apiServer.Close()

	service := CreateComputeService(apiServer.URL)
	flavorsDetail, err := service.FlavorsDetail()
	testUtil.IsNil(t, err)

	if len(flavorsDetail) != 2 {
		t.Error(errors.New("Error: Expected 2 flavors detail to be listed"))
	}
	testUtil.Equals(t, sampleFlavorDetail, flavorsDetail[0])
	testUtil.Equals(t, sampleFlavorDetail2, flavorsDetail[1])
}
func TestGetSubnets(t *testing.T) {
	mockResponseObject := subnetsResp{Subnets: []network.SubnetResponse{sampleSubNetResponse}}
	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObject(t, tokn, mockResponseObject, "/subnets")

	defer apiServer.Close()

	networkService := CreateNetworkService(apiServer.URL)
	subnets, err := networkService.Subnets()
	if err != nil {
		t.Error(err)
	}

	if len(subnets) != 1 {
		t.Error(errors.New("Error: Expected 1 subnet to be listed"))
	}
	testUtil.Equals(t, sampleSubNetResponse, subnets[0])
}
func TestGetFlavors(t *testing.T) {

	mockResponseObject := FlavorsContainer{
		Flavors: []Flavor{sampleFlavor, sampleFlavor2}}

	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObject(t, tokn, mockResponseObject, "/flavors")
	defer apiServer.Close()

	service := CreateDatabaseService(apiServer.URL)
	flavors, err := service.Flavors()
	testUtil.IsNil(t, err)

	if len(flavors) != 2 {
		t.Error(errors.New("Error: Expected 2 flavors to be listed"))
	}
	testUtil.Equals(t, sampleFlavor, flavors[0])
	testUtil.Equals(t, sampleFlavor2, flavors[1])
}
Example #15
0
func TestGetUsers(t *testing.T) {

	mockResponseObject := UsersContainer{
		Users: []User{sampleUser1, sampleUser2}}

	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObject(t, tokn, mockResponseObject, "/users")
	defer apiServer.Close()

	service := CreateDatabaseService(apiServer.URL)
	users, err := service.Users(instanceID)
	if err != nil {
		t.Error(err)
	}

	if len(users) != 2 {
		t.Error(errors.New("Error: Expected 2 users to be listed"))
	}
	testUtil.Equals(t, sampleUser1, users[0])
	testUtil.Equals(t, sampleUser2, users[1])
}
func TestGetVolumeAttachments(t *testing.T) {

	mockResponseObject := volumeAttachmentsResp{VolumeAttachments: []VolumeAttachment{sampleVolumeAttachment}}
	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObject(t, tokn, mockResponseObject, "/servers/serverID/os-volume_attachments")
	defer apiServer.Close()

	service := CreateComputeService(apiServer.URL)

	attachedVolumes, err := service.VolumeAttachments("serverID")
	if err != nil {
		t.Fatal(err)
	}

	if len(attachedVolumes) != 1 {
		t.Fatal(errors.New("Error: Expected 1 volume to be attached"))
	}

	testUtil.Equals(t, sampleVolumeAttachment, attachedVolumes[0])

}
func TestGetDatabases(t *testing.T) {

	mockResponseObject := DatabasesContainer{
		Databases: []Database{sampleDatabase1, sampleDatabase2}}

	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObject(t, tokn, mockResponseObject, "/databases")
	defer apiServer.Close()

	service := CreateDatabaseService(apiServer.URL)
	databases, err := service.Databases(instanceID)
	if err != nil {
		t.Error(err)
	}

	if len(databases) != 2 {
		t.Error(errors.New("Error: Expected 2 databases to be listed"))
	}
	testUtil.Equals(t, sampleDatabase1, databases[0])
	testUtil.Equals(t, sampleDatabase2, databases[1])
}
func TestQueryNetworks(t *testing.T) {
	mockResponseObject := networksContainer{Networks: []network.Response{sampleNetworkResponse}}
	apiServer := testUtil.CreateGetJSONTestRequestServerWithMockObject(t, tokn, mockResponseObject, "/networks?admin_state_up=true&name=foo&router%3Aexternal=true&shared=true&status=ACTIVE")
	defer apiServer.Close()

	networkService := CreateNetworkService(apiServer.URL)
	qp := network.QueryParameters{
		Name:           "foo",
		Status:         "ACTIVE",
		RouterExternal: true,
		AdminStateUp:   true,
		Shared:         true,
	}

	networks, err := networkService.QueryNetworks(qp)
	if err != nil {
		t.Error(err)
	}

	if len(networks) != 1 {
		t.Error(errors.New("Error: Expected 2 networks to be listed"))
	}
	testUtil.Equals(t, sampleNetworkResponse, networks[0])
}