Skip to content

Commit

Permalink
Leverage connectionName to standardize the name field in response
Browse files Browse the repository at this point in the history
  • Loading branch information
maqiuyujoyce committed Jul 19, 2024
1 parent fe03f3b commit bf146c1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions mockgcp/mockbigqueryconnection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ func (s *ConnectionV1) CreateConnection(ctx context.Context, req *pb.CreateConne

obj := proto.Clone(req.Connection).(*pb.Connection)

// The returned "name" in the response uses the project number instead of
// project ID.
obj.Name = strings.ReplaceAll(fqn, "mock-project", "${projectNumber}")
obj.Name = name.stringInResponse()
obj.CreationTime = now.Unix()
obj.LastModifiedTime = now.Unix()
if obj.GetCloudResource().GetServiceAccountId() == "" {
Expand Down Expand Up @@ -109,6 +107,12 @@ func (n *connectionName) String() string {
return "projects/" + n.Project.ID + "/locations/" + n.Location + "/connections/" + n.ResourceID
}

func (n *connectionName) stringInResponse() string {
// The returned "name" in the response uses the project number instead of
// project ID.
return "projects/${projectNumber}/locations/" + n.Location + "/connections/" + n.ResourceID
}

// parseConnectionName parses a string into a connectionName.
// The expected form is projects/<projectID>/locations/<location>/connections/<connectionID>
func (s *MockService) parseConnectionName(name string) (*connectionName, error) {
Expand Down

0 comments on commit bf146c1

Please sign in to comment.