Fixing indents, adding repo_name option and additional tests

This commit is contained in:
David Dyball 2014-08-08 09:15:32 +01:00
parent 8ac2ca6f42
commit 39695c45bd
2 changed files with 126 additions and 88 deletions

View file

@ -28,6 +28,9 @@ type Docker struct {
RegistryLogin bool `yaml:"registry_login"`
RegistryLoginUri string `yaml:"registry_login_uri"`
// Allow setting Repo + Image names for delivery
// NOTE: RepoName is not compatible with private Registries
RepoName string `yaml:"repo_name"`
ImageName string `yaml:"image_name"`
// Authentication credentials for index.docker.io
@ -52,7 +55,16 @@ type Docker struct {
func (d *Docker) Write(f *buildfile.Buildfile, r *repo.Repo) {
if len(d.DockerServer) == 0 || d.DockerServerPort == 0 || len(d.DockerVersion) == 0 ||
len(d.ImageName) == 0 {
f.WriteCmdSilent(`echo "Docker Plugin: Missing argument(s)"`)
f.WriteCmdSilent(`echo -e "Docker Plugin: Missing argument(s)"\n\n`)
if len(d.DockerServer) == 0 { f.WriteCmdSilent(`echo -e "\tdocker_server not defined in yaml`) }
if d.DockerServerPort == 0 { f.WriteCmdSilent(`echo -e "\tdocker_port not defined in yaml`) }
if len(d.DockerVersion) == 0 { f.WriteCmdSilent(`echo -e "\tdocker_version not defined in yaml`) }
if len(d.ImageName) == 0 { f.WriteCmdSilent(`echo -e "\timage_name not defined in yaml`) }
return
}
if len(d.RepoName) > 0 && len(d.RegistryHost) > 0 {
f.WriteCmdSilent(`echo -e "Docker Plugin: Invalid Arguments Specified\n\n cannot combine repo_name and registry_host\n\t(It's not possible to host sub-repo's on private registries)\n"`)
return
}
@ -76,9 +88,13 @@ func (d *Docker) Write(f *buildfile.Buildfile, r *repo.Repo) {
imageBaseName := ""
if len(d.RegistryHost) > 0 {
imageBaseName = fmt.Sprintf("%s/%s",d.RegistryHost,d.ImageName)
} else {
if len(d.RepoName) > 0 {
imageBaseName = fmt.Sprintf("%s/%s",d.RepoName,d.ImageName)
} else {
imageBaseName = fmt.Sprintf("%s/%s",d.Username,d.ImageName)
}
}
registryLoginEndpoint := ""
@ -102,9 +118,6 @@ func (d *Docker) Write(f *buildfile.Buildfile, r *repo.Repo) {
}
}
//splitRepoName := strings.Split(r.Name, "/")
//dockerRepo := d.ImageName + "/" + splitRepoName[len(splitRepoName)-1]
dockerPath := "."
if len(d.Dockerfile) != 0 {
dockerPath = fmt.Sprintf("- < %s", d.Dockerfile)

View file

@ -24,6 +24,29 @@ func setUpWithDrone(input string) (string, error) {
return bf.String(), err
}
// Private Registry + RepoName (invalid config)
var privateRegistryRepoNameYaml = `
publish:
docker:
docker_server: server
docker_port: 1000
docker_version: 1.0
registry_host: server
registry_login: false
repo_name: company
image_name: image
`
func TestPrivateRegistryRepoName(t *testing.T) {
response, err := setUpWithDrone(privateRegistryRepoNameYaml)
t.Log(privateRegistryRepoNameYaml)
if err != nil {
t.Fatalf("Can't unmarshal script: %s\n\n", err.Error())
}
if !strings.Contains(response, "Docker Plugin: Invalid Arguments Specified") {
t.Fatalf("registry_host + repo_name should produce an invalid config error, it didn't")
}
}
// Private Registry Test (no auth)
var privateRegistryNoAuthYaml = `
@ -39,6 +62,7 @@ publish:
`
func TestPrivateRegistryNoAuth(t *testing.T) {
response, err := setUpWithDrone(privateRegistryNoAuthYaml)
t.Log(privateRegistryNoAuthYaml)
if err != nil {
t.Fatalf("Can't unmarshal script: %s\n\n", err.Error())
}
@ -173,7 +197,7 @@ func TestMissingFields(t *testing.T) {
if err != nil {
t.Fatalf("Can't unmarshal script: %s\n\n", err.Error())
}
if !strings.Contains(response, "echo \"Docker Plugin: Missing argument(s)\"") {
if !strings.Contains(response, "Missing argument(s)") {
t.Fatalf("Response: " + response + " didn't contain missing arguments warning\n\n")
}
}
@ -232,6 +256,7 @@ publish:
func TestWithoutDockerFile(t *testing.T) {
response, err := setUpWithDrone(withoutDockerFileYaml)
t.Log(withoutDockerFileYaml)
if err != nil {
t.Fatalf("Can't unmarshal script: %s\n\n", err.Error())
}