// +build acceptance compute volumeattach

package v2

import (
	"testing"

	"devel.mephi.ru/iacherepanov/openstack-gophercloud/acceptance/clients"
	bs "devel.mephi.ru/iacherepanov/openstack-gophercloud/acceptance/openstack/blockstorage/v2"
	"devel.mephi.ru/iacherepanov/openstack-gophercloud/acceptance/tools"
	th "devel.mephi.ru/iacherepanov/openstack-gophercloud/testhelper"
)

func TestVolumeAttachAttachment(t *testing.T) {
	clients.RequireLong(t)

	client, err := clients.NewComputeV2Client()
	th.AssertNoErr(t, err)

	blockClient, err := clients.NewBlockStorageV2Client()
	th.AssertNoErr(t, err)

	server, err := CreateServer(t, client)
	th.AssertNoErr(t, err)
	defer DeleteServer(t, client, server)

	volume, err := bs.CreateVolume(t, blockClient)
	th.AssertNoErr(t, err)
	defer bs.DeleteVolume(t, blockClient, volume)

	volumeAttachment, err := CreateVolumeAttachment(t, client, blockClient, server, volume)
	th.AssertNoErr(t, err)
	defer DeleteVolumeAttachment(t, client, blockClient, server, volumeAttachment)

	tools.PrintResource(t, volumeAttachment)

	th.AssertEquals(t, volumeAttachment.ServerID, server.ID)
}
