open-nomad/nomad/structs/csi_test.go

31 lines
661 B
Go
Raw Normal View History

2019-10-14 19:51:10 +00:00
package structs
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestCSIVolumeClaim(t *testing.T) {
vol := NewCSIVolume("", 0)
vol.AccessMode = CSIVolumeAccessModeMultiNodeSingleWriter
vol.Schedulable = true
2019-10-14 19:51:10 +00:00
alloc := &Allocation{ID: "a1"}
alloc2 := &Allocation{ID: "a2"}
2019-10-14 19:51:10 +00:00
vol.ClaimRead(alloc)
require.True(t, vol.CanReadOnly())
2019-10-14 19:51:10 +00:00
require.True(t, vol.CanWrite())
require.True(t, vol.ClaimRead(alloc))
2019-10-14 19:51:10 +00:00
vol.ClaimWrite(alloc)
require.True(t, vol.CanReadOnly())
require.False(t, vol.CanWrite())
require.False(t, vol.ClaimWrite(alloc2))
2019-10-14 19:51:10 +00:00
vol.ClaimRelease(alloc)
require.True(t, vol.CanReadOnly())
require.True(t, vol.CanWrite())
}