Repository: apigee/registry
Pull request #912 (2023-01-06 23:19:00)

Fix patterns for revision collection names.
Patterns used to match spec and deployment revision collections were breaking changes that I was testing for #896. Here's the fix in a standalone PR.

timburks: @seaneganx thanks for the review - I'll proceed but @theganyo PTAL

Patch:
diff --git a/server/registry/names/deployment_revision.go b/server/registry/names/deployment_revision.go
index 8fdbacb..0f12a3d 100644
--- a/server/registry/names/deployment_revision.go
+++ b/server/registry/names/deployment_revision.go
@@ -22,7 +22,7 @@ import (
 var deploymentRevisionRegexp = regexp.MustCompile(fmt.Sprintf("^projects/%s/locations/%s/apis/%s/deployments/%s(?:@%s)?$",
 	identifier, Location, identifier, identifier, revisionTag))
 
-var deploymentRevisionCollectionRegexp = regexp.MustCompile(fmt.Sprintf("^projects/%s/locations/%s/apis/%s/deployments/%s@",
+var deploymentRevisionCollectionRegexp = regexp.MustCompile(fmt.Sprintf("^projects/%s/locations/%s/apis/%s/deployments/%s@$",
 	identifier, Location, identifier, identifier))
 
 // DeploymentRevision represents a resource name for an API deployment revision.
diff --git a/server/registry/names/spec_revision.go b/server/registry/names/spec_revision.go
index 637940b..ca2de4f 100644
--- a/server/registry/names/spec_revision.go
+++ b/server/registry/names/spec_revision.go
@@ -22,8 +22,8 @@ import (
 var specRevisionRegexp = regexp.MustCompile(fmt.Sprintf("^projects/%s/locations/%s/apis/%s/versions/%s/specs/%s(?:@%s)?$",
 	identifier, Location, identifier, identifier, identifier, revisionTag))
 
-var specRevisionCollectionRegexp = regexp.MustCompile(fmt.Sprintf("^projects/%s/locations/%s/apis/%s/versions/%s/specs@$",
-	identifier, Location, identifier, identifier))
+var specRevisionCollectionRegexp = regexp.MustCompile(fmt.Sprintf("^projects/%s/locations/%s/apis/%s/versions/%s/specs/%s@$",
+	identifier, Location, identifier, identifier, identifier))
 
 // SpecRevision represents a resource name for an API spec revision.
 type SpecRevision struct {


Test patch:
diff --git a/server/registry/names/names_test.go b/server/registry/names/names_test.go
index 0bd0ef8..ecf243d 100644
--- a/server/registry/names/names_test.go
+++ b/server/registry/names/names_test.go
@@ -161,6 +161,22 @@ func TestResourceNames(t *testing.T) {
 				"projects/google/locations/global/apis/sample/versions/v1/specs/openapi.yaml@1234567890abcdef",
 			},
 		},
+		{
+			name: "spec revision collections",
+			check: func(name string) bool {
+				_, err := ParseSpecRevisionCollection(name)
+				return err == nil
+			},
+			pass: []string{
+				"projects/google/locations/global/apis/sample/versions/v1/specs/s@",
+				"projects/-/locations/global/apis/-/versions/-/specs/-@",
+			},
+			fail: []string{
+				"-",
+				"projects/google/locations/global/apis/sample/versions/v1/specs/s@123",
+				"projects/-/locations/global/apis/-/versions/-/specs/-",
+			},
+		},
 		{
 			name: "spec revision",
 			check: func(name string) bool {
@@ -218,6 +234,22 @@ func TestResourceNames(t *testing.T) {
 				"projects/google/locations/global/apis/sample/deployments/v1@1234567890abcdef",
 			},
 		},
+		{
+			name: "deployment revision collections",
+			check: func(name string) bool {
+				_, err := ParseDeploymentRevisionCollection(name)
+				return err == nil
+			},
+			pass: []string{
+				"projects/google/locations/global/apis/sample/deployments/d@",
+				"projects/-/locations/global/apis/-/deployments/d@",
+			},
+			fail: []string{
+				"-",
+				"projects/google/locations/global/apis/sample/deployments/d@123",
+				"projects/-/locations/global/apis/-/deployments/d",
+			},
+		},
 		{
 			name: "deployment revision",
 			check: func(name string) bool {