-
Notifications
You must be signed in to change notification settings - Fork 0
/
dockerresource_test.go
72 lines (63 loc) · 2.2 KB
/
dockerresource_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
// Copyright 2018 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package resources_test
import (
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/juju/core/resources"
"github.com/juju/juju/docker"
)
type DockerResourceSuite struct{}
var _ = gc.Suite(&DockerResourceSuite{})
func (s *DockerResourceSuite) TestValidRegistryPath(c *gc.C) {
for _, registryTest := range []struct {
registryPath string
}{{
registryPath: "registry.staging.charmstore.com/me/awesomeimage@sha256:5e2c71d050bec85c258a31aa4507ca8adb3b2f5158a4dc919a39118b8879a5ce",
}, {
registryPath: "gcr.io/kubeflow/jupyterhub-k8s@sha256:5e2c71d050bec85c258a31aa4507ca8adb3b2f5158a4dc919a39118b8879a5ce",
}, {
registryPath: "docker.io/me/mygitlab:latest",
}, {
registryPath: "me/mygitlab:latest",
}} {
err := resources.ValidateDockerRegistryPath(registryTest.registryPath)
c.Assert(err, jc.ErrorIsNil)
}
}
func (s *DockerResourceSuite) TestInvalidRegistryPath(c *gc.C) {
err := resources.ValidateDockerRegistryPath("blah:sha256@")
c.Assert(err, gc.ErrorMatches, "docker image path .* not valid")
}
func (s *DockerResourceSuite) TestDockerImageDetailsUnmarshalJson(c *gc.C) {
data := []byte(`{"ImageName":"testing@sha256:beef-deed","Username":"docker-registry","Password":"fragglerock"}`)
result, err := resources.UnmarshalDockerResource(data)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, gc.DeepEquals, resources.DockerImageDetails{
RegistryPath: "testing@sha256:beef-deed",
ImageRepoDetails: docker.ImageRepoDetails{
BasicAuthConfig: docker.BasicAuthConfig{
Username: "docker-registry",
Password: "fragglerock",
},
},
})
}
func (s *DockerResourceSuite) TestDockerImageDetailsUnmarshalYaml(c *gc.C) {
data := []byte(`
registrypath: testing@sha256:beef-deed
username: docker-registry
password: fragglerock
`[1:])
result, err := resources.UnmarshalDockerResource(data)
c.Assert(err, jc.ErrorIsNil)
c.Assert(result, gc.DeepEquals, resources.DockerImageDetails{
RegistryPath: "testing@sha256:beef-deed",
ImageRepoDetails: docker.ImageRepoDetails{
BasicAuthConfig: docker.BasicAuthConfig{
Username: "docker-registry",
Password: "fragglerock",
},
},
})
}