2019-10-14 19:51:10 +00:00
|
|
|
package structs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCSIVolumeClaim(t *testing.T) {
|
2020-02-03 16:59:00 +00:00
|
|
|
vol := NewCSIVolume("", 0)
|
2020-01-08 22:27:43 +00:00
|
|
|
vol.AccessMode = CSIVolumeAccessModeMultiNodeSingleWriter
|
2020-03-03 15:59:58 +00:00
|
|
|
vol.Schedulable = true
|
2019-10-14 19:51:10 +00:00
|
|
|
|
2020-03-13 13:39:24 +00:00
|
|
|
alloc := &Allocation{ID: "a1"}
|
|
|
|
alloc2 := &Allocation{ID: "a2"}
|
2019-10-14 19:51:10 +00:00
|
|
|
|
|
|
|
vol.ClaimRead(alloc)
|
2020-01-08 22:27:43 +00:00
|
|
|
require.True(t, vol.CanReadOnly())
|
2019-10-14 19:51:10 +00:00
|
|
|
require.True(t, vol.CanWrite())
|
2020-01-08 22:27:43 +00:00
|
|
|
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())
|
2020-03-13 13:39:24 +00:00
|
|
|
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())
|
|
|
|
}
|