|
| 1 | +/* |
| 2 | +Copyright 2020 The Tekton Authors |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
1 | 17 | package volumeclaim
|
2 | 18 |
|
3 | 19 | import (
|
@@ -94,3 +110,44 @@ func TestCreatePersistentVolumeClaimsForWorkspaces(t *testing.T) {
|
94 | 110 | t.Fatalf("unexptected name in ownerreference on created PVC; expected: %s got %s", ownerName, pvc.OwnerReferences[0].Name)
|
95 | 111 | }
|
96 | 112 | }
|
| 113 | + |
| 114 | +// TestCreatePersistentVolumeClaimsForWorkspacesWithoutMetadata tests that given a volumeClaimTemplate workspace |
| 115 | +// without a metadata part, a PVC is created, with the expected name. |
| 116 | +func TestCreatePersistentVolumeClaimsForWorkspacesWithoutMetadata(t *testing.T) { |
| 117 | + |
| 118 | + // given |
| 119 | + |
| 120 | + // workspace with volumeClaimTemplate without metadata |
| 121 | + workspaceName := "ws-with-volume-claim-template-without-metadata" |
| 122 | + ownerName := "taskrun1" |
| 123 | + workspaces := []v1alpha1.WorkspaceBinding{{ |
| 124 | + Name: workspaceName, |
| 125 | + VolumeClaimTemplate: &corev1.PersistentVolumeClaim{ |
| 126 | + Spec: corev1.PersistentVolumeClaimSpec{}, |
| 127 | + }, |
| 128 | + }} |
| 129 | + |
| 130 | + ownerRef := metav1.OwnerReference{Name: ownerName} |
| 131 | + namespace := "ns" |
| 132 | + fakekubeclient := fakek8s.NewSimpleClientset() |
| 133 | + pvcHandler := defaultPVCHandler{fakekubeclient, zap.NewExample().Sugar()} |
| 134 | + |
| 135 | + // when |
| 136 | + |
| 137 | + err := pvcHandler.CreatePersistentVolumeClaimsForWorkspaces(workspaces, ownerRef, namespace) |
| 138 | + if err != nil { |
| 139 | + t.Fatalf("unexpexted error: %v", err) |
| 140 | + } |
| 141 | + |
| 142 | + expectedPVCName := fmt.Sprintf("%s-%s", workspaceName, ownerName) |
| 143 | + pvc, err := fakekubeclient.CoreV1().PersistentVolumeClaims(namespace).Get(expectedPVCName, metav1.GetOptions{}) |
| 144 | + if err != nil { |
| 145 | + t.Fatalf("unexpected error: %v", err) |
| 146 | + } |
| 147 | + |
| 148 | + // that |
| 149 | + |
| 150 | + if pvc.Name != expectedPVCName { |
| 151 | + t.Fatalf("unexpected PVC name on created PVC; exptected: %s got: %s", expectedPVCName, pvc.Name) |
| 152 | + } |
| 153 | +} |
0 commit comments