1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
// Copyright (c) 2018-2020, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
package shub
import (
"fmt"
"os"
"testing"
"github.com/sylabs/singularity/v4/internal/pkg/test"
useragent "github.com/sylabs/singularity/v4/pkg/util/user-agent"
)
var validShubURIs = []string{
`shub://username/container`,
`shub://username/container:tag`,
`shub://username/container@00000000000000000000000000000000`,
`shub://registry/username/container`,
`shub://registry/with/levels/username/container`,
`shub://registry/user-name/container-with-dash`,
`shub://registry/username/container.with.period`,
`shub://username/container:tag-with-dash`,
`shub://username/container:tag_wtih_underscore`,
`shub://username/container:tag.with.period`,
`shub://myprivateregistry.sylabs.io/sylabs/container:latest`,
}
func TestMain(m *testing.M) {
useragent.InitValue("singularity", "3.0.0-alpha.1-303-gaed8d30-dirty")
os.Exit(m.Run())
}
// TestShubParser checks if the Shub ref parser is working as expected
func TestIsShubPullRef(t *testing.T) {
test.DropPrivilege(t)
defer test.ResetPrivilege(t)
invalidShubURIs := []string{
`shub://username/`,
`shub://username/container:`,
`shub://username/container@`,
`shub://username/container@0000000000000000000000000000000`,
`shub://username/container@000000000000000000000000000000000`,
`shub://username/container@abcdefghijklmnopqrstuvwxyz123456`,
`shub://registry/user.name/container`,
`shub://username.with.period/container:tag`,
`shub://-username/container:`,
`shub://username-/container:`,
`shub://-registry/username/container:`,
`shub://registry-/username/container:`,
}
for _, uri := range validShubURIs {
t.Run(fmt.Sprintf("Valid URI: %v", uri),
func(t *testing.T) {
ok := isShubPullRef(uri)
if !ok {
t.Fatalf("failed to parse valid URI: %v", uri)
}
})
}
for _, uri := range invalidShubURIs {
t.Run(fmt.Sprintf("Invalid URI: %v", uri),
func(t *testing.T) {
ok := isShubPullRef(uri)
if ok {
t.Fatalf("failed to parse valid URI: %v", uri)
}
})
}
}
func TestShubParser(t *testing.T) {
for _, uri := range validShubURIs {
t.Run(fmt.Sprintf("Valid URI: %v", uri),
func(t *testing.T) {
sURI, err := ParseReference(uri)
if err != nil {
t.Fatalf("failed to parse valid URI: %v", uri)
}
fmt.Println(sURI.String())
})
}
}
|