Skip to content
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
44 changes: 44 additions & 0 deletions cmd/service/parent_regex_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright The Linux Foundation and each contributor to LFX.
// SPDX-License-Identifier: MIT

package service

import (
"regexp"
"testing"
)

// parentPattern mirrors the Goa design pattern at design/query-svc.go.
// This test exists to guard against accidental regex regression.
const parentPattern = `^[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_-]+$`

func TestParentPattern(t *testing.T) {
re := regexp.MustCompile(parentPattern)

valid := []string{
"project:123",
"past_meeting:98471391296-1765832400000",
"v1_meeting:abc-123",
"v1_past_meeting:foo_bar-baz",
"committee:abc",
}
for _, v := range valid {
if !re.MatchString(v) {
t.Errorf("expected %q to match parent pattern", v)
}
}

invalid := []string{
"past_meeting:", // empty id fragment
":abc", // empty type fragment
"_leading:abc", // leading underscore in type
"past meeting:abc", // space in type
"project", // missing colon
"", // empty
}
for _, v := range invalid {
if re.MatchString(v) {
t.Errorf("expected %q to NOT match parent pattern", v)
}
}
}
3 changes: 2 additions & 1 deletion design/query-svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var _ = dsl.Service("query-svc", func() {
})
dsl.Attribute("parent", dsl.String, "Parent (for navigation; varies by object type)", func() {
dsl.Example("project:123")
dsl.Pattern(`^[a-zA-Z]+:[a-zA-Z0-9_-]+$`)
dsl.Pattern(`^[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_-]+$`)
})
dsl.Attribute("type", dsl.String, "Resource type to search", func() {
dsl.Example("committee")
Expand Down Expand Up @@ -145,6 +145,7 @@ var _ = dsl.Service("query-svc", func() {
})
dsl.Attribute("parent", dsl.String, "Parent (for navigation; varies by object type)", func() {
dsl.Example("project:123")
dsl.Pattern(`^[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_-]+$`)
})
dsl.Attribute("type", dsl.String, "Resource type to search", func() {
dsl.Example("committee")
Expand Down
2 changes: 1 addition & 1 deletion gen/http/openapi.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion gen/http/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ paths:
description: Parent (for navigation; varies by object type)
required: false
type: string
pattern: ^[a-zA-Z]+:[a-zA-Z0-9_-]+$
pattern: ^[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_-]+$
- name: type
in: query
description: Resource type to search
Expand Down Expand Up @@ -322,6 +322,7 @@ paths:
description: Parent (for navigation; varies by object type)
required: false
type: string
pattern: ^[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_-]+$
- name: type
in: query
description: Resource type to search
Expand Down
2 changes: 1 addition & 1 deletion gen/http/openapi3.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion gen/http/openapi3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ paths:
type: string
description: Parent (for navigation; varies by object type)
example: project:123
pattern: ^[a-zA-Z]+:[a-zA-Z0-9_-]+$
pattern: ^[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_-]+$
example: project:123
- name: type
in: query
Expand Down Expand Up @@ -484,6 +484,7 @@ paths:
type: string
description: Parent (for navigation; varies by object type)
example: project:123
pattern: ^[a-zA-Z][a-zA-Z0-9_]*:[a-zA-Z0-9_-]+$
example: project:123
- name: type
in: query
Expand Down
6 changes: 5 additions & 1 deletion gen/http/query_svc/client/cli.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion gen/http/query_svc/server/encode_decode.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading