Skip to content

Commit

Permalink
Merge pull request GoogleCloudPlatform#2742 from yuwenma/bqcc-externa…
Browse files Browse the repository at this point in the history
…l-ref-fix

fix: bigqueryconnectionconnection misuse projectNum for projectID
  • Loading branch information
google-oss-prow[bot] authored Sep 19, 2024
2 parents 4e1d38a + dd47424 commit 0432fc9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
5 changes: 3 additions & 2 deletions mockgcp/mockbigqueryconnection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"math/rand"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -155,11 +156,11 @@ type connectionName struct {
}

func (n *connectionName) String() string {
return "projects/" + n.Project.ID + "/locations/" + n.Location + "/connections/" + n.ResourceID
return "projects/" + strconv.FormatInt(n.Project.Number, 10) + "/locations/" + n.Location + "/connections/" + n.ResourceID
}

// parseConnectionName parses a string into a connectionName.
// The expected form is projects/<projectID>/locations/<location>/connections/<connectionID>
// The expected form is projects/<projectNum>/locations/<location>/connections/<connectionID>
func (s *MockService) parseConnectionName(name string) (*connectionName, error) {
tokens := strings.Split(name, "/")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,14 @@ func (a *Adapter) Create(ctx context.Context, createOp *directbase.CreateOperati
if mapCtx.Err() != nil {
return mapCtx.Err()
}
status.ExternalRef = &created.Name

tokens := strings.Split(created.Name, "/")
parent, err = a.id.Parent()
if err != nil {
return err
}
externalRef := parent + "/connections/" + tokens[5]
status.ExternalRef = &externalRef
return setStatus(u, status)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ X-Xss-Protection: 0
},
"creationTime": "123456789",
"lastModifiedTime": "123456789",
"name": "projects/${projectId}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be"
"name": "projects/${projectNumber}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be"
}

---
Expand All @@ -51,7 +51,7 @@ X-Xss-Protection: 0
},
"creationTime": "123456789",
"lastModifiedTime": "123456789",
"name": "projects/${projectId}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be"
"name": "projects/${projectNumber}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be"
}

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ X-Xss-Protection: 0
{
"error": {
"code": 404,
"message": "Not found: Connection projects/${projectId}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be",
"message": "Not found: Connection projects/${projectNumber}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be",
"status": "NOT_FOUND"
}
}
Expand Down Expand Up @@ -54,7 +54,7 @@ X-Xss-Protection: 0
"description": "test connection for cloud resource",
"friendlyName": "cloud-resource-connection",
"lastModifiedTime": "123456789",
"name": "projects/${projectId}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be"
"name": "projects/${projectNumber}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be"
}

---
Expand Down Expand Up @@ -83,7 +83,7 @@ X-Xss-Protection: 0
"description": "test connection for cloud resource",
"friendlyName": "cloud-resource-connection",
"lastModifiedTime": "123456789",
"name": "projects/${projectId}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be"
"name": "projects/${projectNumber}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be"
}

---
Expand Down Expand Up @@ -118,7 +118,7 @@ X-Xss-Protection: 0
"description": "updated connection for cloud resource",
"friendlyName": "cloud-resource-connection-updated",
"lastModifiedTime": "123456789",
"name": "projects/${projectId}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be"
"name": "projects/${projectNumber}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be"
}

---
Expand Down Expand Up @@ -147,7 +147,7 @@ X-Xss-Protection: 0
"description": "updated connection for cloud resource",
"friendlyName": "cloud-resource-connection-updated",
"lastModifiedTime": "123456789",
"name": "projects/${projectId}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be"
"name": "projects/${projectNumber}/locations/us-central1/connections/71389360-831c-431d-8975-837aee2153be"
}

---
Expand Down

0 comments on commit 0432fc9

Please sign in to comment.