-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
54 lines (48 loc) · 1.32 KB
/
main_test.go
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
package main
import (
"strings"
"testing"
)
func TestParseNameConformance(t *testing.T) {
cases := []string{
"/v2/test/image/manifests/tagtest0",
"/v2/test/image/tags/list",
}
t.Log(cases)
}
func TestParseNameBlobsUploads(t *testing.T) {
withUploads, err := parseName("/v2/some/long/chained/repo/name/blobs/uploads")
if err != nil {
t.Fatal(err)
}
expected := "some/long/chained/repo/name"
if strings.Compare(withUploads, expected) != 0 {
t.Errorf("want %s, got %s", expected, withUploads)
}
}
func TestParseNameBlobsDigest(t *testing.T) {
withDigest, err := parseName("/v2/some/long/chained/repo/name/blobs/sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")
if err != nil {
t.Fatal(err)
}
expected := "some/long/chained/repo/name"
if strings.Compare(withDigest, expected) != 0 {
t.Errorf("want %s, got %s", expected, withDigest)
}
}
func TestParseNameManifests(t *testing.T) {
withDigest, err := parseName("/v2/test/image/manifests/tagtest0")
if err != nil {
t.Fatal(err)
}
expected := "test/image"
if strings.Compare(withDigest, expected) != 0 {
t.Errorf("want %s, got %s", expected, withDigest)
}
}
func TestMatchInvalidRef(t *testing.T) {
m := matches(refRegex, "sha256:totallywrong")
if m {
t.Errorf("Wanted false, got true: %s != %s", refRegex, "sha256:totallywrong")
}
}