Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Describe valid project name on error #362

Merged
merged 3 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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