-
Notifications
You must be signed in to change notification settings - Fork 28
/
scanner_test.go
30 lines (27 loc) · 1.12 KB
/
scanner_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
package main
import (
"testing"
)
func TestImageParsing(t *testing.T) {
cases := [][4]string{
{"alpine:3.17", "", "alpine", "3.17"},
{"nginx:latest", "", "nginx", "latest"},
{"nginx", "", "nginx", "latest"},
{"nginx:", "", "nginx", ""},
{"test/nginx", "", "test/nginx", "latest"},
{"test/nginx:v2", "", "test/nginx", "v2"},
{"example.com:5000", "https://example.com:5000", "", ""},
{"example.com/test/nginx:v2", "https://example.com", "test/nginx", "v2"},
{"example.com:5000/test/nginx:v2", "https://example.com:5000", "test/nginx", "v2"},
{"http://example.com:5000/test/nginx:v2", "http://example.com:5000", "test/nginx", "v2"},
{"http://example.com:5000/nginx:2.1", "http://example.com:5000", "nginx", "2.1"},
{"registry.hub.docker.com/python:3.4", "https://registry.hub.docker.com", "library/python", "3.4"},
{"registry.hub.docker.com/test/python:3.4", "https://registry.hub.docker.com", "test/python", "3.4"},
}
for _, c := range cases {
reg, repo, tag := parseImageValue(c[0])
if reg != c[1] || repo != c[2] || tag != c[3] {
t.Errorf("Incorrect result: %s => %s, %s, %s\n", c[0], reg, repo, tag)
}
}
}