Skip to content

Commit

Permalink
Merge pull request #362 from mbland/project-name-error-message
Browse files Browse the repository at this point in the history
  • Loading branch information
ndeloof authored Mar 3, 2023
2 parents 5837d67 + b94d8f4 commit 37ba724
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion cli/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ func NewProjectOptions(configs []string, opts ...ProjectOptionsFn) (*ProjectOpti
func WithName(name string) ProjectOptionsFn {
return func(o *ProjectOptions) error {
if name != loader.NormalizeProjectName(name) {
return fmt.Errorf("%q is not a valid project name", name)
return fmt.Errorf("%q is not a valid project name: it must contain "+
"only characters from [a-z0-9_-] and start with [a-z0-9]", name)
}
o.Name = name
return nil
Expand Down
8 changes: 4 additions & 4 deletions cli/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestProjectName(t *testing.T) {

t.Run("by name start with invalid char '-'", func(t *testing.T) {
_, err := NewProjectOptions([]string{"testdata/simple/compose.yaml"}, WithName("-my_project"))
assert.Error(t, err, `"-my_project" is not a valid project name`)
assert.ErrorContains(t, err, `"-my_project" is not a valid project name`)

opts, err := NewProjectOptions([]string{"testdata/simple/compose.yaml"}, WithEnv([]string{
fmt.Sprintf("%s=%s", consts.ComposeProjectName, "-my_project"),
Expand All @@ -67,7 +67,7 @@ func TestProjectName(t *testing.T) {

t.Run("by name start with invalid char '_'", func(t *testing.T) {
_, err := NewProjectOptions([]string{"testdata/simple/compose.yaml"}, WithName("_my_project"))
assert.Error(t, err, `"_my_project" is not a valid project name`)
assert.ErrorContains(t, err, `"_my_project" is not a valid project name`)

opts, err := NewProjectOptions([]string{"testdata/simple/compose.yaml"}, WithEnv([]string{
fmt.Sprintf("%s=%s", consts.ComposeProjectName, "_my_project"),
Expand All @@ -80,7 +80,7 @@ func TestProjectName(t *testing.T) {

t.Run("by name contains dots", func(t *testing.T) {
_, err := NewProjectOptions([]string{"testdata/simple/compose.yaml"}, WithName("www.my.project"))
assert.Error(t, err, `"www.my.project" is not a valid project name`)
assert.ErrorContains(t, err, `"www.my.project" is not a valid project name`)

opts, err := NewProjectOptions([]string{"testdata/simple/compose.yaml"}, WithEnv([]string{
fmt.Sprintf("%s=%s", consts.ComposeProjectName, "www.my.project"),
Expand All @@ -93,7 +93,7 @@ func TestProjectName(t *testing.T) {

t.Run("by name uppercase", func(t *testing.T) {
_, err := NewProjectOptions([]string{"testdata/simple/compose.yaml"}, WithName("MY_PROJECT"))
assert.Error(t, err, `"MY_PROJECT" is not a valid project name`)
assert.ErrorContains(t, err, `"MY_PROJECT" is not a valid project name`)

opts, err := NewProjectOptions([]string{"testdata/simple/compose.yaml"}, WithEnv([]string{
fmt.Sprintf("%s=%s", consts.ComposeProjectName, "_my_project"),
Expand Down
2 changes: 1 addition & 1 deletion loader/full-example.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Full_Example_project_name
name: full_example_project_name
services:
foo:

Expand Down
1 change: 1 addition & 0 deletions schema/compose-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

"name": {
"type": "string",
"pattern": "^[a-z0-9][a-z0-9_-]*$",
"description": "define the Compose project name, until user defines one explicitly."
},

Expand Down

0 comments on commit 37ba724

Please sign in to comment.