@@ -27,6 +27,46 @@ func TestCreateAndDeleteWorkspace(t *testing.T) {
27
27
}
28
28
}
29
29
30
+ func TestCreateAndDeleteWorkspaceFromWorkspace (t * testing.T ) {
31
+ id , err := g .CreateWorkspace (context .Background (), "directory" )
32
+ if err != nil {
33
+ t .Fatalf ("Error creating workspace: %v" , err )
34
+ }
35
+
36
+ err = g .WriteFileInWorkspace (context .Background (), "file.txt" , []byte ("hello world" ), WriteFileInWorkspaceOptions {
37
+ WorkspaceID : id ,
38
+ })
39
+ if err != nil {
40
+ t .Errorf ("Error creating file: %v" , err )
41
+ }
42
+
43
+ newID , err := g .CreateWorkspace (context .Background (), "directory" , id )
44
+ if err != nil {
45
+ t .Errorf ("Error creating workspace from workspace: %v" , err )
46
+ }
47
+
48
+ data , err := g .ReadFileInWorkspace (context .Background (), "file.txt" , ReadFileInWorkspaceOptions {
49
+ WorkspaceID : newID ,
50
+ })
51
+ if err != nil {
52
+ t .Errorf ("Error reading file: %v" , err )
53
+ }
54
+
55
+ if ! bytes .Equal (data , []byte ("hello world" )) {
56
+ t .Errorf ("Unexpected content: %s" , data )
57
+ }
58
+
59
+ err = g .DeleteWorkspace (context .Background (), id )
60
+ if err != nil {
61
+ t .Errorf ("Error deleting workspace: %v" , err )
62
+ }
63
+
64
+ err = g .DeleteWorkspace (context .Background (), newID )
65
+ if err != nil {
66
+ t .Errorf ("Error deleting new workspace: %v" , err )
67
+ }
68
+ }
69
+
30
70
func TestWriteReadAndDeleteFileFromWorkspace (t * testing.T ) {
31
71
id , err := g .CreateWorkspace (context .Background (), "directory" )
32
72
if err != nil {
@@ -270,6 +310,138 @@ func TestCreateAndDeleteWorkspaceS3(t *testing.T) {
270
310
}
271
311
}
272
312
313
+ func TestCreateAndDeleteWorkspaceFromWorkspaceS3 (t * testing.T ) {
314
+ if os .Getenv ("AWS_ACCESS_KEY_ID" ) == "" || os .Getenv ("AWS_SECRET_ACCESS_KEY" ) == "" || os .Getenv ("WORKSPACE_PROVIDER_S3_BUCKET" ) == "" {
315
+ t .Skip ("Skipping test because AWS credentials are not set" )
316
+ }
317
+
318
+ id , err := g .CreateWorkspace (context .Background (), "s3" )
319
+ if err != nil {
320
+ t .Fatalf ("Error creating workspace: %v" , err )
321
+ }
322
+
323
+ err = g .WriteFileInWorkspace (context .Background (), "file.txt" , []byte ("hello world" ), WriteFileInWorkspaceOptions {
324
+ WorkspaceID : id ,
325
+ })
326
+ if err != nil {
327
+ t .Errorf ("Error creating file: %v" , err )
328
+ }
329
+
330
+ newID , err := g .CreateWorkspace (context .Background (), "s3" , id )
331
+ if err != nil {
332
+ t .Errorf ("Error creating workspace from workspace: %v" , err )
333
+ }
334
+
335
+ data , err := g .ReadFileInWorkspace (context .Background (), "file.txt" , ReadFileInWorkspaceOptions {
336
+ WorkspaceID : newID ,
337
+ })
338
+ if err != nil {
339
+ t .Errorf ("Error reading file: %v" , err )
340
+ }
341
+
342
+ if ! bytes .Equal (data , []byte ("hello world" )) {
343
+ t .Errorf ("Unexpected content: %s" , data )
344
+ }
345
+
346
+ err = g .DeleteWorkspace (context .Background (), id )
347
+ if err != nil {
348
+ t .Errorf ("Error deleting workspace: %v" , err )
349
+ }
350
+
351
+ err = g .DeleteWorkspace (context .Background (), newID )
352
+ if err != nil {
353
+ t .Errorf ("Error deleting new workspace: %v" , err )
354
+ }
355
+ }
356
+
357
+ func TestCreateAndDeleteDirectoryWorkspaceFromWorkspaceS3 (t * testing.T ) {
358
+ if os .Getenv ("AWS_ACCESS_KEY_ID" ) == "" || os .Getenv ("AWS_SECRET_ACCESS_KEY" ) == "" || os .Getenv ("WORKSPACE_PROVIDER_S3_BUCKET" ) == "" {
359
+ t .Skip ("Skipping test because AWS credentials are not set" )
360
+ }
361
+
362
+ id , err := g .CreateWorkspace (context .Background (), "s3" )
363
+ if err != nil {
364
+ t .Fatalf ("Error creating workspace: %v" , err )
365
+ }
366
+
367
+ err = g .WriteFileInWorkspace (context .Background (), "file.txt" , []byte ("hello world" ), WriteFileInWorkspaceOptions {
368
+ WorkspaceID : id ,
369
+ })
370
+ if err != nil {
371
+ t .Errorf ("Error creating file: %v" , err )
372
+ }
373
+
374
+ newID , err := g .CreateWorkspace (context .Background (), "directory" , id )
375
+ if err != nil {
376
+ t .Errorf ("Error creating workspace from workspace: %v" , err )
377
+ }
378
+
379
+ data , err := g .ReadFileInWorkspace (context .Background (), "file.txt" , ReadFileInWorkspaceOptions {
380
+ WorkspaceID : newID ,
381
+ })
382
+ if err != nil {
383
+ t .Errorf ("Error reading file: %v" , err )
384
+ }
385
+
386
+ if ! bytes .Equal (data , []byte ("hello world" )) {
387
+ t .Errorf ("Unexpected content: %s" , data )
388
+ }
389
+
390
+ err = g .DeleteWorkspace (context .Background (), id )
391
+ if err != nil {
392
+ t .Errorf ("Error deleting workspace: %v" , err )
393
+ }
394
+
395
+ err = g .DeleteWorkspace (context .Background (), newID )
396
+ if err != nil {
397
+ t .Errorf ("Error deleting new workspace: %v" , err )
398
+ }
399
+ }
400
+
401
+ func TestCreateAndDeleteS3WorkspaceFromWorkspaceDirectory (t * testing.T ) {
402
+ if os .Getenv ("AWS_ACCESS_KEY_ID" ) == "" || os .Getenv ("AWS_SECRET_ACCESS_KEY" ) == "" || os .Getenv ("WORKSPACE_PROVIDER_S3_BUCKET" ) == "" {
403
+ t .Skip ("Skipping test because AWS credentials are not set" )
404
+ }
405
+
406
+ id , err := g .CreateWorkspace (context .Background (), "s3" )
407
+ if err != nil {
408
+ t .Fatalf ("Error creating workspace: %v" , err )
409
+ }
410
+
411
+ err = g .WriteFileInWorkspace (context .Background (), "file.txt" , []byte ("hello world" ), WriteFileInWorkspaceOptions {
412
+ WorkspaceID : id ,
413
+ })
414
+ if err != nil {
415
+ t .Errorf ("Error creating file: %v" , err )
416
+ }
417
+
418
+ newID , err := g .CreateWorkspace (context .Background (), "directory" , id )
419
+ if err != nil {
420
+ t .Errorf ("Error creating workspace from workspace: %v" , err )
421
+ }
422
+
423
+ data , err := g .ReadFileInWorkspace (context .Background (), "file.txt" , ReadFileInWorkspaceOptions {
424
+ WorkspaceID : newID ,
425
+ })
426
+ if err != nil {
427
+ t .Errorf ("Error reading file: %v" , err )
428
+ }
429
+
430
+ if ! bytes .Equal (data , []byte ("hello world" )) {
431
+ t .Errorf ("Unexpected content: %s" , data )
432
+ }
433
+
434
+ err = g .DeleteWorkspace (context .Background (), id )
435
+ if err != nil {
436
+ t .Errorf ("Error deleting workspace: %v" , err )
437
+ }
438
+
439
+ err = g .DeleteWorkspace (context .Background (), newID )
440
+ if err != nil {
441
+ t .Errorf ("Error deleting new workspace: %v" , err )
442
+ }
443
+ }
444
+
273
445
func TestWriteReadAndDeleteFileFromWorkspaceS3 (t * testing.T ) {
274
446
if os .Getenv ("AWS_ACCESS_KEY_ID" ) == "" || os .Getenv ("AWS_SECRET_ACCESS_KEY" ) == "" || os .Getenv ("WORKSPACE_PROVIDER_S3_BUCKET" ) == "" {
275
447
t .Skip ("Skipping test because AWS credentials are not set" )
0 commit comments