add comments to validation testcases, and use const in util.go

This commit is contained in:
j-griffith
2019-05-30 16:28:09 -06:00
parent 54154f8ebb
commit 60d991e59a
2 changed files with 47 additions and 18 deletions

View File

@@ -13312,24 +13312,48 @@ func testDataSourceInSpec(name string, kind string, apiGroup string) *core.Persi
}
func TestAlphaVolumePVCDataSource(t *testing.T) {
successTestCases := []core.PersistentVolumeClaimSpec{
*testDataSourceInSpec("test_snapshot", "VolumeSnapshot", "snapshot.storage.k8s.io"),
*testDataSourceInSpec("test_pvc", "PersistentVolumeClaim", ""),
}
failedTestCases := []core.PersistentVolumeClaimSpec{
*testDataSourceInSpec("", "VolumeSnapshot", "snapshot.storage.k8s.io"),
*testDataSourceInSpec("test_snapshot", "PersistentVolumeClaim", "snapshot.storage.k8s.io"),
*testDataSourceInSpec("test_snapshot", "VolumeSnapshot", "storage.k8s.io"),
testCases := []struct {
testName string
claimSpec core.PersistentVolumeClaimSpec
expectedFail bool
}{
{
testName: "test create from valid snapshot source",
claimSpec: *testDataSourceInSpec("test_snapshot", "VolumeSnapshot", "snapshot.storage.k8s.io"),
},
{
testName: "test create from valid pvc source",
claimSpec: *testDataSourceInSpec("test_pvc", "PersistentVolumeClaim", ""),
},
{
testName: "test missing name in snapshot datasource should fail",
claimSpec: *testDataSourceInSpec("", "VolumeSnapshot", "snapshot.storage.k8s.io"),
expectedFail: true,
},
{
testName: "test specifying pvc with snapshot api group should fail",
claimSpec: *testDataSourceInSpec("test_snapshot", "PersistentVolumeClaim", "snapshot.storage.k8s.io"),
expectedFail: true,
},
{
testName: "test invalid group name in snapshot datasource should fail",
claimSpec: *testDataSourceInSpec("test_snapshot", "VolumeSnapshot", "storage.k8s.io"),
expectedFail: true,
},
}
for _, tc := range successTestCases {
if errs := ValidatePersistentVolumeClaimSpec(&tc, field.NewPath("spec")); len(errs) != 0 {
t.Errorf("expected success: %v", errs)
}
}
for _, tc := range failedTestCases {
if errs := ValidatePersistentVolumeClaimSpec(&tc, field.NewPath("spec")); len(errs) == 0 {
t.Errorf("expected failure: %v", errs)
for _, tc := range testCases {
if tc.expectedFail {
if errs := ValidatePersistentVolumeClaimSpec(&tc.claimSpec, field.NewPath("spec")); len(errs) == 0 {
t.Errorf("expected failure: %v", errs)
}
} else {
if errs := ValidatePersistentVolumeClaimSpec(&tc.claimSpec, field.NewPath("spec")); len(errs) != 0 {
t.Errorf("expected success: %v", errs)
}
}
}
}