github.com/apptainer/singularity@v3.1.1+incompatible/internal/pkg/build/sources/conveyorPacker_shub_test.go (about) 1 // Copyright (c) 2018, Sylabs Inc. All rights reserved. 2 // This software is licensed under a 3-clause BSD license. Please consult the 3 // LICENSE.md file distributed with the sources of this project regarding your 4 // rights to use or distribute this software. 5 6 package sources_test 7 8 import ( 9 "testing" 10 11 "github.com/sylabs/singularity/internal/pkg/build/sources" 12 "github.com/sylabs/singularity/internal/pkg/test" 13 "github.com/sylabs/singularity/pkg/build/types" 14 ) 15 16 const ( 17 shubURI = "shub://ikaneshiro/singularityhub:latest" 18 ) 19 20 // TestShubConveyor tests if we can pull an image from singularity hub 21 func TestShubConveyor(t *testing.T) { 22 23 if testing.Short() { 24 t.SkipNow() 25 } 26 27 test.DropPrivilege(t) 28 defer test.ResetPrivilege(t) 29 30 b, err := types.NewBundle("", "sbuild-shub") 31 if err != nil { 32 return 33 } 34 35 b.Recipe, err = types.NewDefinitionFromURI(shubURI) 36 if err != nil { 37 t.Fatalf("unable to parse URI %s: %v\n", shubURI, err) 38 } 39 40 cp := &sources.ShubConveyorPacker{} 41 42 err = cp.Get(b) 43 // clean up tmpfs since assembler isnt called 44 defer cp.CleanUp() 45 if err != nil { 46 t.Fatalf("failed to Get from %s: %v\n", shubURI, err) 47 } 48 } 49 50 // TestShubPacker checks if we can create a Bundle from the pulled image 51 func TestShubPacker(t *testing.T) { 52 test.DropPrivilege(t) 53 defer test.ResetPrivilege(t) 54 55 b, err := types.NewBundle("", "sbuild-shub") 56 if err != nil { 57 return 58 } 59 60 b.Recipe, err = types.NewDefinitionFromURI(shubURI) 61 if err != nil { 62 t.Fatalf("unable to parse URI %s: %v\n", shubURI, err) 63 } 64 65 scp := &sources.ShubConveyorPacker{} 66 67 err = scp.Get(b) 68 // clean up tmpfs since assembler isnt called 69 defer scp.CleanUp() 70 if err != nil { 71 t.Fatalf("failed to Get from %s: %v\n", shubURI, err) 72 } 73 74 _, err = scp.Pack() 75 if err != nil { 76 t.Fatalf("failed to Pack from %s: %v\n", shubURI, err) 77 } 78 }