-
Notifications
You must be signed in to change notification settings - Fork 23
/
metadata_test.go
78 lines (70 loc) · 2.01 KB
/
metadata_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package collector
import (
"fmt"
"net/http"
"testing"
config "github.com/banyanops/collector/config"
)
func TestGetLocalImageMetadata(t *testing.T) {
fmt.Println("TestGetLocalImageMetadata")
var e error
DockerClient, e = NewDockerClient(DOCKERPROTO, DOCKERADDR)
if e != nil {
t.Fatal(e)
}
RegistrySpec = config.DockerHub
RegistryAPIURL, HubAPI, BasicAuth, XRegistryAuth = GetRegistryURL()
metadata := ImageMetadataInfo{
OtherMetadata: OtherMetadata{
Repo: "fedora",
Tag: "latest",
},
}
fmt.Println("TestPullImage %v", metadata)
PullImage(&metadata)
var currentMetadataSlice []ImageMetadataInfo
MetadataSet := NewMetadataSet()
LocalHost = true
ReposToProcess[RepoType(metadata.Repo)] = true
currentMetadataSlice = GetLocalImageMetadata(MetadataSet)
for _, localImage := range currentMetadataSlice {
fmt.Println("localImage: ", localImage)
if localImage.Repo == metadata.Repo && localImage.Tag == metadata.Tag {
fmt.Println("TestGetLocalImageMetadata succeeded for ", metadata)
return
}
}
t.Fatal("TestGetLocalImageMetadata failed for ", metadata)
return
}
func TestValidRepoName(t *testing.T) {
testCases := map[string]bool{
"library/ubuntu": true,
"abc/def/ghi": true,
"q:x&2": false,
"banyan/*": true,
"foo*bar/xyz": false,
}
for repo, expected := range testCases {
if ValidRepoName(repo) != expected {
t.Fatalf("TestValidRepoName ValidRepoName(%s) did not return %v", repo, expected)
}
}
}
func TestRegistryQuery(t *testing.T) {
var e error
DockerClient, e = NewDockerClient(DOCKERPROTO, DOCKERADDR)
if e != nil {
t.Fatal(e)
}
RegistrySpec = config.DockerHub
RegistryAPIURL, HubAPI, BasicAuth, XRegistryAuth = GetRegistryURL()
fmt.Printf("RegistryAPIURL %s HubAPI %v BasicAuth %s XRegistryAuth %s\n", RegistryAPIURL, HubAPI, BasicAuth, XRegistryAuth)
*RegistryProto = "v2"
client := &http.Client{}
r, e := RegistryQueryV2(client, "https://"+RegistrySpec+"/v2/banyanops/collector/tags/list")
if e != nil {
t.Fatal(e)
}
fmt.Println(string(r))
}