Exemplo n.º 1
0
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)
}
Exemplo n.º 2
0
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)
}
Exemplo n.º 3
0
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 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)
}
Exemplo n.º 5
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 TestCreateFloatingIP(t *testing.T) {
	mockResponse, _ := json.Marshal(floatingIPContainer{FloatingIP: samplefloatingIP})
	apiServer := testUtil.CreatePostJSONTestRequestServer(t, tokn, string(mockResponse), "os-floating-ips",
		`{"pool":"poolName"}`)
	defer apiServer.Close()

	service := CreateComputeService(apiServer.URL)
	floatingIP, err := service.CreateFloatingIP("poolName")
	if err != nil {
		t.Error(err)
	}

	testUtil.Equals(t, samplefloatingIP, floatingIP)
}
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)
}
Exemplo n.º 8
0
func TestCreatePort(t *testing.T) {
	mockResponse, _ := json.Marshal(portContainer{Port: samplePortResponse})
	apiServer := testUtil.CreatePostJSONTestRequestServer(t, tokn, string(mockResponse), "/ports",
		`{"port":{"admin_state_up":true,"name":"name","network_id":"networkid","fixed_ips":[{"ip_address":""},{"ip_address":""}]}}`)
	defer apiServer.Close()

	networkService := CreateNetworkService(apiServer.URL)
	createPortParameters := network.CreatePortParameters{AdminStateUp: true, Name: "name", NetworkID: "networkid", FixedIPs: fixedIps}
	actualPort, err := networkService.CreatePort(createPortParameters)
	if err != nil {
		t.Error(err)
	}

	testUtil.Equals(t, samplePortResponse, actualPort)
}
Exemplo n.º 9
0
func TestCreateSubnet(t *testing.T) {
	mockResponse, err := json.Marshal(subnetResp{Subnet: sampleSubNetResponse})

	apiServer := testUtil.CreatePostJSONTestRequestServer(t, tokn, string(mockResponse), "/subnets",
		`{"subnet":{"network_id":"subnetid","ip_version":4,"cidr":"12.14.76.87","allocation_pools":[{"start":"13.14.14.15","end":"13.14.14.15"}]}}`)
	defer apiServer.Close()

	networkService := CreateNetworkService(apiServer.URL)
	createSubnetParameters := network.CreateSubnetParameters{NetworkID: "subnetid", AllocationPools: allocationPools, CIDR: "12.14.76.87", IPVersion: 4}
	actualPort, err := networkService.CreateSubnet(createSubnetParameters)
	if err != nil {
		t.Error(err)
	}

	testUtil.Equals(t, sampleSubNetResponse, actualPort)
}
func TestAttachVolume(t *testing.T) {
	mockResponseObject, _ := json.Marshal(volumeAttachmentContainer{VolumeAttachment: sampleVolumeAttachment})
	mockRequestObject, _ := json.Marshal(volumeAttachmentContainer{VolumeAttachment: VolumeAttachment{Device: "/dev/vdd", VolumeID: "volumeID"}})
	apiServer := testUtil.CreatePostJSONTestRequestServer(t, tokn, string(mockResponseObject),
		"/servers/serverID/os-volume_attachments", string(mockRequestObject))
	defer apiServer.Close()

	service := CreateComputeService(apiServer.URL)

	attachedVolume, err := service.AttachVolume("serverID", "volumeID", "/dev/vdd")
	if err != nil {
		t.Fatal(err)
	}

	testUtil.Equals(t, sampleVolumeAttachment, attachedVolume)
}
Exemplo n.º 11
0
func TestCreateNetwork(t *testing.T) {
	mockResponse, _ := json.Marshal(networkContainer{sampleNetworkResponse})
	apiServer := testUtil.CreatePostJSONTestRequestServer(t, tokn, string(mockResponse), "/networks",
		`{"network":{"name":"networkName","admin_state_up":false,"shared":true,"tenant_id":"tenantId"}}`)
	defer apiServer.Close()

	networkService := CreateNetworkService(apiServer.URL)
	params := network.CreateNetworkParameters{
		AdminStateUp: false,
		Shared:       true,
		Name:         "networkName",
		TenantID:     "tenantId"}
	actualNetwork, err := networkService.CreateNetwork(params)
	if err != nil {
		t.Error(err)
	}

	testUtil.Equals(t, sampleNetworkResponse, actualNetwork)
}
func TestCreateSecurityGroupRuleWithGroup(t *testing.T) {
	apiServer := testUtil.CreatePostJSONTestRequestServer(t, tokn, sampleGroupRuleJSONResponse, "/os-security-group-rules",
		`{"security_group_rule":{"from_port":133,"to_port":436,"ip_protocol":"ICMP","group_id":"19ffd595-daba-49f0-91f0-741bac706a3a","parent_group_id":"a226372b-3333-40c4-b4ed-a16e3cb92222","cidr":null}}`)
	defer apiServer.Close()

	groupID := "19ffd595-daba-49f0-91f0-741bac706a3a"

	service := CreateComputeService(apiServer.URL)
	createRule := compute.CreateSecurityGroupRuleParameters{
		FromPort:      133,
		IPProtocol:    icmpValue,
		ParentGroupID: "a226372b-3333-40c4-b4ed-a16e3cb92222",
		ToPort:        436,
		GroupID:       &groupID}

	securityGroupRule, err := service.CreateSecurityGroupRule(createRule)
	testUtil.IsNil(t, err)

	testUtil.Equals(t, sampleGroupRule, securityGroupRule)
}
Exemplo n.º 13
0
func TestCreateVolume(t *testing.T) {
	apiServer := testUtil.CreatePostJSONTestRequestServer(t, tokn, sampleVolumeJSON, "volumes",
		`{"volume":{"display_name":"displayname","availability_zone":"az","display_description":"Description","volume_type":"volType","size":512315}}`)
	defer apiServer.Close()

	createVolumeParameters := blockstorage.CreateVolumeParameters{
		DisplayName: "displayname",
		Az:          "az",
		Desciption:  "Description",
		VolumeType:  "volType",
		Metadata:    map[string]string{},
		Size:        512315,
	}

	service := CreateVolumeService(apiServer.URL)
	volume, err := service.CreateVolume(createVolumeParameters)
	testUtil.IsNil(t, err)

	testUtil.Equals(t, volumeSample, volume)
}