func TestUploadDownloadImage(t *testing.T) {
	client := newClient(t)

	//creating image
	imageName := tools.RandomString("ACCPT", 16)
	containerFormat := "ami"
	createResult := images.Create(client, images.CreateOpts{Name: &imageName,
		ContainerFormat: &containerFormat,
		DiskFormat:      &containerFormat})
	th.AssertNoErr(t, createResult.Err)
	image, err := createResult.Extract()
	th.AssertNoErr(t, err)
	t.Logf("Image %v", image)

	//checking status
	image, err = images.Get(client, image.ID).Extract()
	th.AssertNoErr(t, err)
	th.AssertEquals(t, image.Status, images.ImageStatusQueued)

	//uploading image data
	data := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9}
	putImageResult := images.PutImageData(client, image.ID, bytes.NewReader(data))
	th.AssertNoErr(t, putImageResult.Err)

	//checking status
	image, err = images.Get(client, image.ID).Extract()
	th.AssertNoErr(t, err)
	th.AssertEquals(t, image.Status, images.ImageStatusActive)
	th.AssertEquals(t, *image.SizeBytes, 9)

	//downloading image data
	reader, err := images.GetImageData(client, image.ID).Extract()
	th.AssertNoErr(t, err)
	receivedData, err := ioutil.ReadAll(reader)
	t.Logf("Received data %v", receivedData)
	th.AssertNoErr(t, err)
	th.AssertByteArrayEquals(t, data, receivedData)

	//deteting image
	deleteResult := images.Delete(client, image.ID)
	th.AssertNoErr(t, deleteResult.Err)

}
func TestCreateDeleteImage(t *testing.T) {
	client := newClient(t)
	imageName := tools.RandomString("ACCPT", 16)
	containerFormat := "ami"
	createResult := images.Create(client, images.CreateOpts{Name: &imageName,
		ContainerFormat: &containerFormat,
		DiskFormat:      &containerFormat})

	th.AssertNoErr(t, createResult.Err)
	image, err := createResult.Extract()
	th.AssertNoErr(t, err)

	t.Logf("Image %v", image)

	image, err = images.Get(client, image.ID).Extract()
	th.AssertNoErr(t, err)

	th.AssertEquals(t, image.Status, images.ImageStatusQueued)

	deleteResult := images.Delete(client, image.ID)
	th.AssertNoErr(t, deleteResult.Err)
}
Exemple #3
0
func deleteImage(t *testing.T, client *gophercloud.ServiceClient, image images.Image) {
	//deteting image
	deleteResult := images.Delete(client, image.ID)
	th.AssertNoErr(t, deleteResult.Err)
}