pv controller test: more test cases

The main goal was to cover retrieval of a PVC from the apiserver when
it isn't known yet. This is achieved by adding PVCs and (for the sake
of completeness) PVs to the reactor, but not the controller, when a
special annotation is set. The approach with a special annotation was
chosen because it doesn't affect other tests.

The other test cases were added while checking the existing tests
because (at least at first glance) the situations seemed to be not
covered.
This commit is contained in:
Patrick Ohly
2020-10-28 10:40:42 +01:00
parent 22f81e9e0b
commit 24f5764787
3 changed files with 56 additions and 0 deletions

View File

@@ -95,6 +95,11 @@ type controllerTest struct {
test testCall
}
// annSkipLocalStore can be used to mark initial PVs or PVCs that are meant to be added only
// to the fake apiserver (i.e. available via Get) but not to the local store (i.e. the controller
// won't have them in its cache).
const annSkipLocalStore = "pv-testing-skip-local-store"
type testCall func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor, test controllerTest) error
const testNamespace = "default"
@@ -641,9 +646,15 @@ func runSyncTests(t *testing.T, tests []controllerTest, storageClasses []*storag
}
reactor := newVolumeReactor(client, ctrl, nil, nil, test.errors)
for _, claim := range test.initialClaims {
if metav1.HasAnnotation(claim.ObjectMeta, annSkipLocalStore) {
continue
}
ctrl.claims.Add(claim)
}
for _, volume := range test.initialVolumes {
if metav1.HasAnnotation(volume.ObjectMeta, annSkipLocalStore) {
continue
}
ctrl.volumes.store.Add(volume)
}
reactor.AddClaims(test.initialClaims)