-
Notifications
You must be signed in to change notification settings - Fork 1.2k
test: improve coverage for dataconnect names #10350
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
Open
joehan
wants to merge
3
commits into
next
Choose a base branch
from
test/dataconnect-names
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+69
−86
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,93 +1,76 @@ | ||
| import { expect } from "chai"; | ||
| import * as names from "./names"; | ||
| import { | ||
| parseServiceName, | ||
| parseConnectorName, | ||
| parseCloudSQLInstanceName, | ||
| isGraphqlName, | ||
| } from "./names"; | ||
|
|
||
| describe("names.ts", () => { | ||
| describe("dataconnect/names", () => { | ||
| describe("parseServiceName", () => { | ||
| const cases: { | ||
| desc: string; | ||
| input: string; | ||
| want: { | ||
| projectId?: string; | ||
| location?: string; | ||
| serviceId?: string; | ||
| error?: boolean; | ||
| }; | ||
| }[] = [ | ||
| { | ||
| desc: "should parse a well formed service name, and convert back", | ||
| input: "projects/proj/locations/us-central1/services/serve", | ||
| want: { | ||
| projectId: "proj", | ||
| location: "us-central1", | ||
| serviceId: "serve", | ||
| }, | ||
| }, | ||
| { | ||
| desc: "should error on an invalid service name", | ||
| input: "projects/proj/locations/us-central1/functions/funky", | ||
| want: { | ||
| error: true, | ||
| }, | ||
| }, | ||
| ]; | ||
| for (const c of cases) { | ||
| it(c.desc, () => { | ||
| try { | ||
| const got = names.parseServiceName(c.input); | ||
| expect(got.projectId).to.equal(c.want.projectId); | ||
| expect(got.location).to.equal(c.want.location); | ||
| expect(got.serviceId).to.equal(c.want.serviceId); | ||
| expect(got.toString()).to.equal(c.input); | ||
| } catch (err) { | ||
| expect(c.want.error, `Unexpected error: ${err}`).to.be.true; | ||
| } | ||
| }); | ||
| } | ||
| it("should parse valid service name", () => { | ||
| const name = "projects/my-project/locations/us-central1/services/my-service"; | ||
| const res = parseServiceName(name); | ||
| expect(res.projectId).to.equal("my-project"); | ||
| expect(res.location).to.equal("us-central1"); | ||
| expect(res.serviceId).to.equal("my-service"); | ||
| expect(res.toString()).to.equal(name); | ||
| }); | ||
|
|
||
| it("should throw on invalid service name", () => { | ||
| expect(() => parseServiceName("invalid-name")).to.throw(/not a valid service name/); | ||
| }); | ||
| }); | ||
|
|
||
| describe("parseConnectorName", () => { | ||
| const cases: { | ||
| desc: string; | ||
| input: string; | ||
| want: { | ||
| projectId?: string; | ||
| location?: string; | ||
| serviceId?: string; | ||
| connectorId?: string; | ||
| error?: boolean; | ||
| }; | ||
| }[] = [ | ||
| { | ||
| desc: "should parse a well formed service name, and convert back", | ||
| input: "projects/proj/locations/us-central1/services/serve/connectors/connect", | ||
| want: { | ||
| projectId: "proj", | ||
| location: "us-central1", | ||
| serviceId: "serve", | ||
| connectorId: "connect", | ||
| }, | ||
| }, | ||
| { | ||
| desc: "should error on an invalid connector name", | ||
| input: "projects/proj/locations/us-central1/functions/funky", | ||
| want: { | ||
| error: true, | ||
| }, | ||
| }, | ||
| ]; | ||
| for (const c of cases) { | ||
| it(c.desc, () => { | ||
| try { | ||
| const got = names.parseConnectorName(c.input); | ||
| expect(got.projectId).to.equal(c.want.projectId); | ||
| expect(got.location).to.equal(c.want.location); | ||
| expect(got.serviceId).to.equal(c.want.serviceId); | ||
| expect(got.connectorId).to.equal(c.want.connectorId); | ||
| expect(got.toString()).to.equal(c.input); | ||
| } catch (err) { | ||
| expect(c.want.error, `Unexpected error: ${err}`).to.be.true; | ||
| } | ||
| }); | ||
| } | ||
| it("should parse valid connector name", () => { | ||
| const name = | ||
| "projects/my-project/locations/us-central1/services/my-service/connectors/my-connector"; | ||
| const res = parseConnectorName(name); | ||
| expect(res.projectId).to.equal("my-project"); | ||
| expect(res.location).to.equal("us-central1"); | ||
| expect(res.serviceId).to.equal("my-service"); | ||
| expect(res.connectorId).to.equal("my-connector"); | ||
| expect(res.toString()).to.equal(name); | ||
| }); | ||
|
|
||
| it("should throw on invalid connector name", () => { | ||
| expect(() => parseConnectorName("projects/my-project/services/only")).to.throw( | ||
| /not a valid connector name/, | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("parseCloudSQLInstanceName", () => { | ||
| it("should parse valid CloudSQL instance name", () => { | ||
| const name = "projects/my-project/locations/us-central1/instances/my-instance"; | ||
| const res = parseCloudSQLInstanceName(name); | ||
| expect(res.projectId).to.equal("my-project"); | ||
| expect(res.location).to.equal("us-central1"); | ||
| expect(res.instanceId).to.equal("my-instance"); | ||
| expect(res.toString()).to.equal( | ||
| "projects/my-project/locations/us-central1/instances/my-instance", | ||
| ); | ||
| }); | ||
|
|
||
| it("should throw on invalid CloudSQL instance name", () => { | ||
| expect(() => parseCloudSQLInstanceName("invalid")).to.throw( | ||
| /not a valid cloudSQL instance name/, | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("isGraphqlName", () => { | ||
| it("should validate correct names", () => { | ||
| expect(isGraphqlName("User")).to.be.true; | ||
| expect(isGraphqlName("_test")).to.be.true; | ||
| expect(isGraphqlName("Test123")).to.be.true; | ||
| }); | ||
|
|
||
| it("should invalidate wrong names", () => { | ||
| expect(isGraphqlName("1User")).to.be.false; | ||
| expect(isGraphqlName("user-name")).to.be.false; | ||
| expect(isGraphqlName("")).to.be.false; | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.