@@ -14,11 +14,8 @@ import (
1414
1515 . "github.com/onsi/ginkgo/v2"
1616 . "github.com/onsi/gomega"
17- "google.golang.org/grpc/codes"
18- "google.golang.org/grpc/status"
1917 corev1 "k8s.io/api/core/v1"
2018 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21-
2219 "sigs.k8s.io/controller-runtime/pkg/client"
2320)
2421
@@ -104,7 +101,7 @@ var _ = Describe("CreateVolume", func() {
104101 },
105102 VolumeDataSource : & iri.VolumeDataSource {
106103 SnapshotDataSource : & iri.SnapshotDataSource {
107- SnapshotId : "test-snapshot-id " ,
104+ SnapshotId : "test-snapshot" ,
108105 },
109106 },
110107 },
@@ -124,119 +121,4 @@ var _ = Describe("CreateVolume", func() {
124121 Expect (ironcoreVolume .Spec .VolumeDataSource .VolumeSnapshotRef .Name ).To (Equal ("test-snapshot" ))
125122 })
126123
127- It ("should return error if snapshot is not found" , func (ctx SpecContext ) {
128- By ("creating a volume with non-existent snapshot data source" )
129- res , err := srv .CreateVolume (ctx , & iri.CreateVolumeRequest {
130- Volume : & iri.Volume {
131- Metadata : & irimeta.ObjectMetadata {
132- Labels : map [string ]string {
133- volumepoolletv1alpha1 .VolumeUIDLabel : "foobar" ,
134- },
135- },
136- Spec : & iri.VolumeSpec {
137- Class : volumeClass .Name ,
138- Resources : & iri.VolumeResources {
139- StorageBytes : 100 ,
140- },
141- VolumeDataSource : & iri.VolumeDataSource {
142- SnapshotDataSource : & iri.SnapshotDataSource {
143- SnapshotId : "non-existent-snapshot-id" ,
144- },
145- },
146- },
147- },
148- })
149-
150- Expect (err ).To (HaveOccurred ())
151- Expect (res ).To (BeNil ())
152- Expect (status .Code (err )).To (Equal (codes .NotFound ))
153- })
154-
155- It ("should return error if snapshot is in pending state" , func (ctx SpecContext ) {
156- By ("creating a volume snapshot in pending state" )
157- volumeSnapshot := & storagev1alpha1.VolumeSnapshot {
158- ObjectMeta : metav1.ObjectMeta {
159- Namespace : ns .Name ,
160- Name : "pending-snapshot" ,
161- },
162- Spec : storagev1alpha1.VolumeSnapshotSpec {
163- VolumeRef : & corev1.LocalObjectReference {Name : "source-volume" },
164- },
165- Status : storagev1alpha1.VolumeSnapshotStatus {
166- State : storagev1alpha1 .VolumeSnapshotStatePending ,
167- SnapshotID : "pending-snapshot-id" ,
168- },
169- }
170- Expect (k8sClient .Create (ctx , volumeSnapshot )).To (Succeed ())
171-
172- By ("creating a volume with pending snapshot data source" )
173- res , err := srv .CreateVolume (ctx , & iri.CreateVolumeRequest {
174- Volume : & iri.Volume {
175- Metadata : & irimeta.ObjectMetadata {
176- Labels : map [string ]string {
177- volumepoolletv1alpha1 .VolumeUIDLabel : "foobar" ,
178- },
179- },
180- Spec : & iri.VolumeSpec {
181- Class : volumeClass .Name ,
182- Resources : & iri.VolumeResources {
183- StorageBytes : 100 ,
184- },
185- VolumeDataSource : & iri.VolumeDataSource {
186- SnapshotDataSource : & iri.SnapshotDataSource {
187- SnapshotId : "pending-snapshot-id" ,
188- },
189- },
190- },
191- },
192- })
193-
194- Expect (err ).To (HaveOccurred ())
195- Expect (res ).To (BeNil ())
196- Expect (status .Code (err )).To (Equal (codes .FailedPrecondition ))
197- })
198-
199- It ("should return error if snapshot is in failed state" , func (ctx SpecContext ) {
200- By ("creating a volume snapshot in failed state" )
201- volumeSnapshot := & storagev1alpha1.VolumeSnapshot {
202- ObjectMeta : metav1.ObjectMeta {
203- Namespace : ns .Name ,
204- Name : "failed-snapshot" ,
205- },
206- Spec : storagev1alpha1.VolumeSnapshotSpec {
207- VolumeRef : & corev1.LocalObjectReference {Name : "source-volume" },
208- },
209- Status : storagev1alpha1.VolumeSnapshotStatus {
210- State : storagev1alpha1 .VolumeSnapshotStateFailed ,
211- SnapshotID : "failed-snapshot-id" ,
212- },
213- }
214- Expect (k8sClient .Create (ctx , volumeSnapshot )).To (Succeed ())
215-
216- By ("creating a volume with failed snapshot data source" )
217- res , err := srv .CreateVolume (ctx , & iri.CreateVolumeRequest {
218- Volume : & iri.Volume {
219- Metadata : & irimeta.ObjectMetadata {
220- Labels : map [string ]string {
221- volumepoolletv1alpha1 .VolumeUIDLabel : "foobar" ,
222- },
223- },
224- Spec : & iri.VolumeSpec {
225- Class : volumeClass .Name ,
226- Resources : & iri.VolumeResources {
227- StorageBytes : 100 ,
228- },
229- VolumeDataSource : & iri.VolumeDataSource {
230- SnapshotDataSource : & iri.SnapshotDataSource {
231- SnapshotId : "failed-snapshot-id" ,
232- },
233- },
234- },
235- },
236- })
237-
238- Expect (err ).To (HaveOccurred ())
239- Expect (res ).To (BeNil ())
240- Expect (status .Code (err )).To (Equal (codes .Internal ))
241- })
242124})
0 commit comments