Skip to content

Commit

Permalink
model: docker compose target validation (#1206)
Browse files Browse the repository at this point in the history
  • Loading branch information
maiamcc authored Feb 25, 2019
1 parent 1dc3250 commit 115d3c5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/model/deploy_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ func (t DockerComposeTarget) Dependencies() []string {

func (dc DockerComposeTarget) Validate() error {
if dc.ID().Empty() {
return fmt.Errorf("[Validate] DockerCompose resources missing name:\n%s", dc.YAMLRaw)
return fmt.Errorf("[Validate] DockerCompose resource missing name:\n%s", dc.YAMLRaw)
}

if dc.ConfigPath == "" {
return fmt.Errorf("[Validate] DockerCompose resource %s missing config path", dc.Name)
}

return nil
Expand Down
20 changes: 20 additions & 0 deletions internal/model/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,5 +378,25 @@ func TestManifestValidateMountRelativePath(t *testing.T) {
manifest = manifest.WithImageTarget(ImageTarget{Ref: img1}.WithBuildDetails(fbInfo))
err = manifest.Validate()
assert.Nil(t, err)
}

func TestDCTargetValidate(t *testing.T) {
targ := DockerComposeTarget{
Name: "blah",
ConfigPath: "docker-compose.yml",
}
err := targ.Validate()
assert.NoError(t, err)

noConfPath := DockerComposeTarget{Name: "blah"}
err = noConfPath.Validate()
if assert.Error(t, err) {
assert.Contains(t, err.Error(), "missing config path")
}

noName := DockerComposeTarget{ConfigPath: "docker-compose.yml"}
err = noName.Validate()
if assert.Error(t, err) {
assert.Contains(t, err.Error(), "missing name")
}
}

0 comments on commit 115d3c5

Please sign in to comment.