func TestServiceURLComputeV3Returns(t *testing.T) {
	sc := []service{createService("computev3", "nova", testEndpoints...)}

	url, err := getComputeServiceURL("t", nil, sc, "compute", "region1", "3")
	testUtil.IsNil(t, err)
	testUtil.Equals(t, "http://endpoint1", url)
}
func TestCreateServer(t *testing.T) {
	apiServer := testUtil.CreatePostJSONTestRequestServer(t, tokn, createServerJSONPayload, "servers",
		`{"server":{"name":"my_server","imageRef":"8c3cd338-1282-4fbb-bbaf-2256ff97c7b7","key_name":"my_key_name","flavorRef":"101","maxcount":1,"mincount":1,"user_data":"my_user_data","availability_zone":"az1","networks":[{"uuid":"1111d337-0282-4fbb-bbaf-2256ff97c7b7","port":"881"}],"security_groups":[{"name":"my_security_group_123"}]}}`)
	defer apiServer.Close()

	serverService := CreateComputeService(apiServer.URL)
	az := "az1"
	userData := "my_user_data"
	maxMinCount := int32(1)
	var serverCreationParameters = ServerCreationParameters{
		Name:             "my_server",
		ImageRef:         "8c3cd338-1282-4fbb-bbaf-2256ff97c7b7",
		KeyPairName:      "my_key_name",
		FlavorRef:        "101",
		MaxCount:         &maxMinCount,
		MinCount:         &maxMinCount,
		AvailabilityZone: &az,
		UserData:         &userData,
		Networks:         []ServerNetworkParameters{ServerNetworkParameters{UUID: "1111d337-0282-4fbb-bbaf-2256ff97c7b7", Port: "881"}},
		SecurityGroups:   []SecurityGroup{SecurityGroup{Name: "my_security_group_123"}}}

	result, err := serverService.CreateServer(serverCreationParameters)
	testUtil.IsNil(t, err)

	testUtil.Equals(t, createServerResponse, result)
}
func TestDelete(t *testing.T) {
	var apiServer = testUtil.CreateDeleteTestRequestServer(t, token, "/other")
	defer apiServer.Close()

	err := util.Delete(apiServer.URL+"/other", token, *http.DefaultClient)
	testUtil.IsNil(t, err)
}
func TestServiceURLNetworkV3Returns(t *testing.T) {
	sc := []service{createService("network", "neutron", testEndpoints...)}

	url, err := getAppendVersionServiceURL("t", nil, sc, "network", "region2", "3")
	testUtil.IsNil(t, err)
	testUtil.Equals(t, "http://endpoint2/v3", url)
}
func TestFindEndpointVersionNoValueFoundNoErrorShouldOccur(t *testing.T) {
	apiServer := testUtil.CreateGetJSONTestRequestServerVerifyURL(t, tokn, hpHelionImageVersionPayload, "")
	defer apiServer.Close()

	url, err := FindEndpointVersion(apiServer.URL, tokn, nil, "v2.0")
	testUtil.IsNil(t, err)
	testUtil.Equals(t, "", url)
}
func TestDefaultServiceURLFoundInCatalogFoundInVersionList(t *testing.T) {
	apiServer := testVersionList(t)
	defer apiServer.Close()
	sc := []service{createService("image", "glance", endpoint{Region: "region1", PublicURL: apiServer.URL + "/publicurl", VersionList: apiServer.URL + "/versionlist"})}
	url, err := defaultGetVersionURLFilterByVersion("t", nil, sc, "image", "region1", "1")
	testUtil.IsNil(t, err)
	testUtil.Equals(t, "http://region-b.geo-1.image.hpcloudsvc.com/v1/", url)
}
func TestFindEndpointVersionValid(t *testing.T) {
	apiServer := testUtil.CreateGetJSONTestRequestServerVerifyURL(t, tokn, hpHelionImageVersionPayload, "")
	defer apiServer.Close()

	url, err := FindEndpointVersion(apiServer.URL, tokn, nil, "v1.0")
	testUtil.IsNil(t, err)
	testUtil.Equals(t, "http://region-a.geo-1.images.hpcloudsvc.com/v1/", url)
}
func TestCreateUser(t *testing.T) {
	apiServer := testUtil.CreatePostJSONTestRequestServer(t, tokn, "", "/instances/InstanceID/users",
		`{"users":[{"name":"username","password":"******"}]}`)
	defer apiServer.Close()

	service := CreateDatabaseService(apiServer.URL)
	err := service.CreateUser("InstanceID", UserParameter{Name: "username", Password: "******"})
	testUtil.IsNil(t, err)
}
func TestGetVolumeType(t *testing.T) {
	apiServer := testUtil.CreateGetJSONTestRequestServerVerifyStatusAndURL(t, tokn, 200, sampleVolumeTypeJson, "/types/id")
	defer apiServer.Close()

	service := CreateVolumeService(apiServer.URL)
	volume, err := service.VolumeType("id")
	testUtil.IsNil(t, err)
	testUtil.Equals(t, volumeTypeSample, volume)
}
func TestDeleteVolumeType(t *testing.T) {
	name := "id"
	apiServer := testUtil.CreateDeleteTestRequestServer(t, tokn, "types/"+name)
	defer apiServer.Close()

	service := CreateVolumeService(apiServer.URL)
	err := service.DeleteVolumeType(name)
	testUtil.IsNil(t, err)
}
Example #11
0
func TestDeleteUser(t *testing.T) {
	name := "user"
	apiServer := testUtil.CreateDeleteTestRequestServer(t, tokn, "/instanceID/users/"+name)
	defer apiServer.Close()

	service := CreateDatabaseService(apiServer.URL)
	err := service.DeleteUser("instanceID", name)
	testUtil.IsNil(t, err)
}
func TestCreateDatabase(t *testing.T) {
	apiServer := testUtil.CreatePostJSONTestRequestServer(t, tokn, "", "/instances/InstanceID/databases",
		`{"databases":[{"character_set":"utf32","collate":"latin","name":"username"}]}`)
	defer apiServer.Close()

	service := CreateDatabaseService(apiServer.URL)
	err := service.CreateDatabases("InstanceID", CreateDatabaseParameters{Name: "username", CharacterSet: "utf32", Collate: "latin"})
	testUtil.IsNil(t, err)
}
func TestGetSecurityGroup(t *testing.T) {
	apiServer := testUtil.CreateGetJSONTestRequestServerVerifyURL(t, tokn, sampleSecurityGroupJSONResponse, "/os-security-groups/w9236264")
	defer apiServer.Close()

	service := CreateComputeService(apiServer.URL)
	sg, err := service.SecurityGroup("w9236264")
	testUtil.IsNil(t, err)
	testUtil.Equals(t, sampleSecurityGroup, sg)
}
func TestDeleteSecurityGroupRule(t *testing.T) {
	name := "securitygrouprule"
	apiServer := testUtil.CreateDeleteTestRequestServer(t, tokn, "/os-security-group-rules/"+name)
	defer apiServer.Close()

	service := CreateComputeService(apiServer.URL)
	err := service.DeleteSecurityGroupRule(name)
	testUtil.IsNil(t, err)
}
func TestGetVolumeTypes(t *testing.T) {
	apiServer := testUtil.CreateGetJSONTestRequestServerVerifyStatusAndURL(t, tokn, 200, sampleVolumeTypesJson, "/types")
	defer apiServer.Close()

	service := CreateVolumeService(apiServer.URL)
	volumes, err := service.VolumeTypes()
	testUtil.IsNil(t, err)
	testUtil.Assert(t, len(volumes) == 1, "Expected 1 volume")
	testUtil.Equals(t, volumeTypeSample, volumes[0])
}
func TestDeleteServer(t *testing.T) {

	apiServer := testUtil.CreateDeleteTestRequestServer(t, tokn, "/servers/server")
	defer apiServer.Close()

	serverService := CreateComputeService(apiServer.URL)

	err := serverService.DeleteServer("server")
	testUtil.IsNil(t, err)
}
func TestGetServerSecurityGroups(t *testing.T) {
	apiServer := testUtil.CreateGetJSONTestRequestServerVerifyURL(t, tokn, sampleSecurityGroupsJSONResponse, "/os-security-groups/servers/aghagr")
	defer apiServer.Close()

	service := CreateComputeService(apiServer.URL)
	sgs, err := service.ServerSecurityGroups("aghagr")
	testUtil.IsNil(t, err)
	testUtil.Equals(t, len(sgs), 1)
	testUtil.Equals(t, sampleSecurityGroup, sgs[0])
}
func createVolumeTypeTest(t *testing.T, p blockstorage.CreateVolumeTypeParameters, expectedPayload string) {
	apiServer := testUtil.CreatePostJSONTestRequestServer(t, tokn, sampleVolumeTypeJson, "types", expectedPayload)
	defer apiServer.Close()

	service := CreateVolumeService(apiServer.URL)
	volume, err := service.CreateVolumeType(p)
	testUtil.IsNil(t, err)

	testUtil.Equals(t, volumeTypeSample, volume)
}
func TestServerDetailNoImage(t *testing.T) {
	apiServer := testUtil.CreateGetJSONTestRequestServerVerifyURL(t, tokn, serverDetailNoImagePayload, "/servers/my_server")
	defer apiServer.Close()

	service := CreateComputeService(apiServer.URL)

	result, err := service.ServerDetail("my_server")
	testUtil.IsNil(t, err)

	testUtil.Equals(t, serverDetailNoImage, result)
}
func authenticate(t *testing.T) (string, common.Authenticator, common.AuthenticationParameters) {
	ap := getAuthenticationParameters(t)
	authenticator := identity.Authenticate(ap)
	authenticator.SetFunction(requester.DebugRequestMakerGenerator(nil, nil, testing.Verbose()))

	tokenID, err := authenticator.GetToken()
	testUtil.IsNil(t, err)
	testUtil.Assert(t, tokenID != "", "No tokenID was found.")

	return tokenID, &authenticator, ap
}
Example #21
0
func TestPostJsonWithValidResponse(t *testing.T) {
	var apiServer = testUtil.CreatePostJSONTestRequestServer(t, token, `{"id":"id1","name":"Chris"}`, "", `{"id":"id1","name":"name"}`)
	defer apiServer.Close()
	actual := TestStruct{}
	ti := TestStruct{ID: "id1", Name: "name"}

	err := util.PostJSON(apiServer.URL, token, *http.DefaultClient, ti, &actual)
	testUtil.IsNil(t, err)
	expected := TestStruct{ID: "id1", Name: "Chris"}

	testUtil.Equals(t, expected, actual)
}
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 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 TestQueryServersDetail(t *testing.T) {
	apiServer := testUtil.CreateGetJSONTestRequestServerVerifyURL(t, tokn, serversDetailJSONPayload, "/servers/detail?limit=21&name=foo")
	defer apiServer.Close()

	computeService := CreateComputeService(apiServer.URL)
	queryParameters := ServerDetailQueryParameters{Name: "foo"}
	servers, err := computeService.QueryServersDetail(queryParameters)

	testUtil.IsNil(t, err)
	testUtil.Assert(t, len(servers) == 1, "Expected 1 server.")
	testUtil.Equals(t, serverDetail, servers[0])
}
func TestCreateSecurityGroup(t *testing.T) {
	apiServer := testUtil.CreatePostJSONTestRequestServer(t, tokn, sampleSecurityGroupJSONResponse, "/os-security-groups",
		`{"security_group":{"tenant_id":"tenantID","addSecurityGroup":"addsecgroup","name":"name","description":"Description"}}`)
	defer apiServer.Close()

	service := CreateComputeService(apiServer.URL)
	parameters := compute.CreateSecurityGroupParameters{TenantID: "tenantID", AddSecurityGroup: "addsecgroup",
		Name: "name", Description: "Description"}

	securityGroup, err := service.CreateSecurityGroup(parameters)
	testUtil.IsNil(t, err)

	testUtil.Equals(t, sampleSecurityGroup, securityGroup)
}
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 TestEndpoints(t *testing.T) {
	apiServer := testUtil.CreateGetJSONTestRequestServerVerifyURL(t, tokn, hpHelionImageVersionPayload, "")
	defer apiServer.Close()

	versions, err := Endpoints(apiServer.URL, tokn, nil)
	testUtil.IsNil(t, err)
	numVersions := len(versions)
	testUtil.Equals(t, 2, numVersions)

	testUtil.Equals(t, "v1.1", versions[0].ID)
	testUtil.Equals(t, "CURRENT", versions[0].Status)

	testUtil.Equals(t, "v1.0", versions[1].ID)
	testUtil.Equals(t, "SUPPORTED", versions[1].Status)
}
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 getServiceURLInitialize(t *testing.T, serviceType string) (string, string, common.AuthenticationParameters, common.Authenticator) {
	if testing.Short() {
		t.Skip("skipping test in short mode.")
	}

	version, ok := currentRunningMap[serviceType]
	if !ok {
		t.Skip("skipping test as the service type is not in the map specifying the version to use.")
	}

	tokenID, authenticator, ap := authenticate(t)
	serviceURL, err := authenticator.GetServiceURL(serviceType, version)
	testUtil.IsNil(t, err)
	testUtil.Assert(t, serviceURL != "", "No service URL was found.")

	return tokenID, serviceURL, ap, authenticator
}
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])
}