Skip to content

Commit

Permalink
Test pv/namespace waiters
Browse files Browse the repository at this point in the history
Signed-off-by: Nolan Brubaker <nolan@heptio.com>
  • Loading branch information
Nolan Brubaker committed Oct 4, 2018
1 parent 3e9bf33 commit 251bafe
Showing 1 changed file with 95 additions and 0 deletions.
95 changes: 95 additions & 0 deletions pkg/restore/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,101 @@ func TestExecutePVAction(t *testing.T) {
}
}

func TestWaiters(t *testing.T) {
t.Run("pv waiter test", func(t *testing.T) {
pv := `apiVersion: v1
kind: PersistentVolume
metadata:
annotations:
EXPORT_block: "\nEXPORT\n{\n\tExport_Id = 1;\n\tPath = /export/pvc-6a74b5af-78a5-11e8-a0d8-e2ad1e9734ce;\n\tPseudo
= /export/pvc-6a74b5af-78a5-11e8-a0d8-e2ad1e9734ce;\n\tAccess_Type = RW;\n\tSquash
= no_root_squash;\n\tSecType = sys;\n\tFilesystem_id = 1.1;\n\tFSAL {\n\t\tName
= VFS;\n\t}\n}\n"
Export_Id: "1"
Project_Id: "0"
Project_block: ""
Provisioner_Id: 5fdf4025-78a5-11e8-9ece-0242ac110004
kubernetes.io/createdby: nfs-dynamic-provisioner
pv.kubernetes.io/provisioned-by: example.com/nfs
volume.beta.kubernetes.io/mount-options: vers=4.1
creationTimestamp: 2018-06-25T18:27:35Z
finalizers:
- kubernetes.io/pv-protection
name: pvc-6a74b5af-78a5-11e8-a0d8-e2ad1e9734ce
resourceVersion: "2576"
selfLink: /api/v1/persistentvolumes/pvc-6a74b5af-78a5-11e8-a0d8-e2ad1e9734ce
uid: 6ecd24e4-78a5-11e8-a0d8-e2ad1e9734ce
spec:
accessModes:
- ReadWriteMany
capacity:
storage: 1Mi
claimRef:
apiVersion: v1
kind: PersistentVolumeClaim
name: nfs
namespace: default
resourceVersion: "2565"
uid: 6a74b5af-78a5-11e8-a0d8-e2ad1e9734ce
nfs:
path: /export/pvc-6a74b5af-78a5-11e8-a0d8-e2ad1e9734ce
server: 10.103.235.254
storageClassName: example-nfs
status:
phase: Bound`
obj, _, err := scheme.Codecs.UniversalDecoder(v1.SchemeGroupVersion).Decode([]byte(pv), nil, nil)
require.NoError(t, err)
pvObj, ok := obj.(*v1.PersistentVolume)
require.True(t, ok)

pvw := &pvWaiter{chans: make(map[string]chan *v1.PersistentVolume)}

pvw.addDeleteChan(pvObj.Name)

go func() {
deleteChan, _ := pvw.getDeleteChan(pvObj.Name)
deleteChan <- pvObj
pvw.removeDeleteChan(pvObj.Name)
}()

// Sending something on the channel should cause the waiter to wake up
res, err := pvw.waitForDelete(pvObj.Name, time.Second*2)
require.NoError(t, err)
assert.Equal(t, pvObj, res)

// Force a time out by making it extrememly low.
res, err = pvw.waitForDelete(pvObj.Name, time.Second*0)
require.Error(t, err)
assert.Equal(t, (*v1.PersistentVolume)(nil), res)
})

t.Run("namespace waiter test", func(t *testing.T) {
ns := newTestNamespace("ns1").Namespace

nsw := &namespaceWaiter{chans: make(map[string]chan *v1.Namespace)}

nsw.addDeleteChan(ns.Name)

go func() {
deleteChan, _ := nsw.getDeleteChan(ns.Name)
deleteChan <- ns
nsw.removeDeleteChan(ns.Name)
}()

// Sending something on the channel should cause the waiter to wake up
res, err := nsw.waitForDelete(ns.Name, time.Second*2)
require.NoError(t, err)
assert.Equal(t, ns, res)

// Force a time out by making it extrememly low.
res, err = nsw.waitForDelete(ns.Name, time.Second*0)
require.Error(t, err)
var expected *v1.Namespace
assert.Equal(t, expected, res)
})

}

func TestIsPVReady(t *testing.T) {
tests := []struct {
name string
Expand Down

0 comments on commit 251bafe

Please sign in to comment.