2016-09-27 13:19:45 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015 The Kubernetes Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package flocker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-12-14 23:22:28 +00:00
|
|
|
"os"
|
2016-09-27 13:19:45 +00:00
|
|
|
"testing"
|
|
|
|
|
2017-06-22 17:25:57 +00:00
|
|
|
"k8s.io/api/core/v1"
|
2016-09-27 13:19:45 +00:00
|
|
|
"k8s.io/kubernetes/pkg/volume"
|
2016-10-12 10:22:01 +00:00
|
|
|
volumetest "k8s.io/kubernetes/pkg/volume/testing"
|
2016-09-27 13:19:45 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFlockerUtil_CreateVolume(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
|
|
|
// test CreateVolume happy path
|
2016-11-18 20:58:56 +00:00
|
|
|
pvc := volumetest.CreateTestPVC("3Gi", []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce})
|
2016-09-27 13:19:45 +00:00
|
|
|
options := volume.VolumeOptions{
|
2018-10-05 19:59:38 +00:00
|
|
|
PVC: pvc,
|
2016-11-18 20:58:56 +00:00
|
|
|
PersistentVolumeReclaimPolicy: v1.PersistentVolumeReclaimDelete,
|
2016-09-27 13:19:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fakeFlockerClient := newFakeFlockerClient()
|
2016-12-14 23:22:28 +00:00
|
|
|
dir, p := newTestableProvisioner(assert, options)
|
|
|
|
provisioner := p.(*flockerVolumeProvisioner)
|
|
|
|
defer os.RemoveAll(dir)
|
2016-09-27 13:19:45 +00:00
|
|
|
provisioner.flockerClient = fakeFlockerClient
|
|
|
|
|
2018-10-09 05:42:52 +00:00
|
|
|
flockerUtil := &flockerUtil{}
|
2016-09-27 13:19:45 +00:00
|
|
|
|
|
|
|
datasetID, size, _, err := flockerUtil.CreateVolume(provisioner)
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.Equal(datasetOneID, datasetID)
|
|
|
|
assert.Equal(3, size)
|
|
|
|
|
|
|
|
// test error during CreateVolume
|
|
|
|
fakeFlockerClient.Error = fmt.Errorf("Do not feel like provisioning")
|
|
|
|
_, _, _, err = flockerUtil.CreateVolume(provisioner)
|
|
|
|
assert.Equal(fakeFlockerClient.Error.Error(), err.Error())
|
|
|
|
}
|