Fixes dependencies for old docker client and tests introduced by merge of #49.

This commit is contained in:
Manuel Vogel 2018-10-28 21:00:44 +01:00
parent be72bcafb0
commit 496abe0578
No known key found for this signature in database
GPG key ID: 533006C7B61DB1CE
3 changed files with 2 additions and 145 deletions

View file

@ -185,32 +185,6 @@ type internalPullImageOptions struct {
func parseImageOptions(image string) internalPullImageOptions {
pullOpts := internalPullImageOptions{}
// splitImageName := strings.Split(image, ":")
// switch len(splitImageName) {
// // It's in registry:port/username/repo:tag or registry:port/repo:tag format
// case 3:
// splitPortRepo := strings.Split(splitImageName[1], "/")
// pullOpts.Registry = splitImageName[0] + ":" + splitPortRepo[0]
// pullOpts.Tag = splitImageName[2]
// pullOpts.Repository = pullOpts.Registry + "/" + strings.Join(splitPortRepo[1:], "/")
// // It's either registry:port/username/repo, registry:port/repo
// // or repo:tag with default registry
// case 2:
// splitPortRepo := strings.Split(splitImageName[1], "/")
// switch len(splitPortRepo) {
// // repo:tag
// case 1:
// pullOpts.Repository = splitImageName[0]
// pullOpts.Tag = splitImageName[1]
// // registry:port/username/repo or registry:port/repo
// default:
// pullOpts.Registry = splitImageName[0] + ":" + splitPortRepo[0]
// pullOpts.Repository = pullOpts.Registry + "/" + strings.Join(splitPortRepo[1:], "/")
// pullOpts.Tag = "latest"
// }
// Pre-fill with image by default, update later if tag found
pullOpts.Repository = image

View file

@ -1,117 +0,0 @@
package docker
import (
"github.com/fsouza/go-dockerclient"
"testing"
)
func TestParseRegistryPortTagFormat(t *testing.T) {
validatePullOpts(t,
"registry.gitlab.com:443/foo/bar:v1",
&docker.PullImageOptions{
Registry: "registry.gitlab.com:443",
Repository: "registry.gitlab.com:443/foo/bar",
Tag: "v1",
})
validatePullOpts(t,
"registry.gitlab.com:443/foo:v1",
&docker.PullImageOptions{
Registry: "registry.gitlab.com:443",
Repository: "registry.gitlab.com:443/foo",
Tag: "v1",
})
}
func TestParseRegistryPortFormat(t *testing.T) {
validatePullOpts(t,
"registry.gitlab.com:443/foo/bar",
&docker.PullImageOptions{
Registry: "registry.gitlab.com:443",
Repository: "registry.gitlab.com:443/foo/bar",
Tag: "",
})
validatePullOpts(t,
"registry.gitlab.com:443/foo",
&docker.PullImageOptions{
Registry: "registry.gitlab.com:443",
Repository: "registry.gitlab.com:443/foo",
Tag: "",
})
}
func TestParseRepoTagFormat(t *testing.T) {
validatePullOpts(t,
"foo:bar",
&docker.PullImageOptions{
Registry: "",
Repository: "foo",
Tag: "bar",
})
}
func TestParseRegistryRepoFormat(t *testing.T) {
validatePullOpts(t,
"registry.gitlab.com/foo/bar",
&docker.PullImageOptions{
Registry: "registry.gitlab.com",
Repository: "registry.gitlab.com/foo/bar",
Tag: "",
})
}
func TestParsePlainRepoFormat(t *testing.T) {
validatePullOpts(t,
"foo/bar",
&docker.PullImageOptions{
Registry: "",
Repository: "foo/bar",
Tag: "",
})
}
func TestParseGitlabComThreePartImageOptions(t *testing.T) {
validatePullOpts(t,
"registry.gitlab.com:443/foo/bar/baz:v1",
&docker.PullImageOptions{
Registry: "registry.gitlab.com:443",
Repository: "registry.gitlab.com:443/foo/bar/baz",
Tag: "v1",
})
validatePullOpts(t,
"registry.gitlab.com:443/foo/bar/baz",
&docker.PullImageOptions{
Registry: "registry.gitlab.com:443",
Repository: "registry.gitlab.com:443/foo/bar/baz",
Tag: "",
})
validatePullOpts(t,
"registry.gitlab.com/foo/bar/baz:v1",
&docker.PullImageOptions{
Registry: "registry.gitlab.com",
Repository: "registry.gitlab.com/foo/bar/baz",
Tag: "v1",
})
validatePullOpts(t,
"registry.gitlab.com/foo/bar/baz",
&docker.PullImageOptions{
Registry: "registry.gitlab.com",
Repository: "registry.gitlab.com/foo/bar/baz",
Tag: "",
})
}
func validatePullOpts(t *testing.T, inputString string, expected *docker.PullImageOptions) {
pullOpts := parseImageOptions(inputString)
if pullOpts.Registry != expected.Registry {
t.Fatalf("For '%s' expected registry '%s', got '%s'", inputString, expected.Registry, pullOpts.Registry)
}
if pullOpts.Repository != expected.Repository {
t.Fatalf("For '%s' expected repository '%s', got '%s'", inputString, expected.Repository, pullOpts.Repository)
}
if pullOpts.Tag != expected.Tag {
t.Fatalf("For '%s' expected tag '%s', got '%s'", inputString, expected.Tag, pullOpts.Tag)
}
}

View file

@ -69,8 +69,8 @@ data "docker_registry_image" "quay" {
```
-> **Note**
When passing in a config file make sure every repo in the `auths` object has
an `auth` string. If not you'll get an `ErrCannotParseDockercfg` by the underlying `go-dockerclient`. On OSX the `auth` base64 string is stored in the `osxkeychain`, but reading from there is not yet supported. See [go-dockerclient#677](https://github.com/fsouza/go-dockerclient/issues/677) for details.
When passing in a config file make sure every repo in the `auths` object should have
a corresponding `auth` string.
In this case, either use `username` and `password` directly or set the enviroment variables `DOCKER_REGISTRY_USER` and `DOCKER_REGISTRY_PASS` or add the string manually via