Skip to content
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

test: v4 signed URL: conformance test #638

Merged
merged 5 commits into from
Apr 1, 2019
Merged

Conversation

jkwlui
Copy link
Member

@jkwlui jkwlui commented Mar 22, 2019

No description provided.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 22, 2019
conformance-test/v4SignedUrl.ts Outdated Show resolved Hide resolved
});

// tslint:disable-next-line:no-any
testCases.forEach((testCase: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this pattern, when a test fails - you're going to get a stack trace that points to code in a loop. How are we going to know specifically which code is failing? I don't have a great answer, but I personally really dislike debugging these kinds of tests-in-a-loopsie-loop thingies. Wondering if @bcoe has an answer.

Copy link
Contributor

@bcoe bcoe Mar 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never loved this pattern in tests (auto generating the description feels pretty clever, and makes it hard to grep the codebase for a specific test case).

I might instead look into using a snapshot pattern, it's really similar but addresses some of @JustinBeckwith's concerns, and I think is a really cool pattern to have in our tool-belt. It works like this:

You have a unit test with an assertion that looks like this:

test.js

  it('reports coverage for script that exits normally', () => {
    const { output } = runSomeOperation()
    output.should.matchSnapshot()
  })

You have a snapshot file that maps the assertion names to captured outputs:

test.js.snapshot

exports[`reports coverage for script that exits normally`] = {"recorded snapshot output": "foo bar"};

You tend to pair this pattern with some process for generation, and you run the snapshots in generation mode when changes have been made -- in your case this might be changes to a fixture.


Here's the library I've been using to add this functionality to mocha, I really love it:

https://www.npmjs.com/package/chai-jest-snapshot

conformance-test/v4SignedUrl.ts Outdated Show resolved Hide resolved
conformance-test/v4SignedUrl.ts Outdated Show resolved Hide resolved
conformance-test/v4SignedUrl.ts Outdated Show resolved Hide resolved
conformance-test/v4SignedUrl.ts Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't block landing this on introducing snapshots, but I think they're potentially a great abstraction for adding this type of test to code-bases and worth considering.

Copy link
Contributor

@JustinBeckwith JustinBeckwith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - only ask - please file a follow up issue to clean up the tests happening in a loop. We don't need to do it in this PR, but it's a good thing as a cleanup label to go explore snapshots.

@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Mar 29, 2019
@jkwlui jkwlui merged commit e9d74fb into v4-signedurl Apr 1, 2019
@jkwlui jkwlui deleted the v4-conformance-test branch April 1, 2019 18:29
jkwlui added a commit that referenced this pull request Apr 4, 2019
* feat: v4 signed url WIP

* make version an optinoal

* lint

* add required host header

* fix canonical query params joining

* add test for defaulting to v2

* fix v4 signing with test

* fix tests

* refactor post-signing url construction v2/v4

* add v4 tests: response-content-type and generate parameters

* convert signature to HEX

* add conformance test

* npm run fix

* remove reduntant toLowerCase

* do not promisify getDate()

* add system-test for v4 signing

* run conformance test along with system test

* fix tests

* add content-md5 and content-type to signed headers if given

* Object.entries in not ES5

* npm run fix

* split out conformance test

* test: invalid version param given

* mock out Date when testing instead of override Date

* use Array.map to build canonical query

* refactor: use dateformat library instead of writing a function

* refactor: remove unused

* remove reference to deleted methods

* refactor: use string interpolation and dot accessor

* refactor: use method chaining

* add a comment about singled valued header

* refactor signedHeaders

* Number(x)

* refactor: use query-string module as url.parse is deprecated

* npm run fix

* use query-string to build canonicalQueryParams

* refactor: verb => method

* refactor: use sinon.FakeTimers instead of timekeeper

* npm run fix

* use async/await for new system-test

* use async/await for new test (2)

* convert getSignedUrl tests to async/await

* refactor: correctly filter out undefined header values

* npm run fix

* make v4 multi-valued header delimiter consistent with v2, (single `,`, no space)

* copy stack trace

* fix: replace ALL sequential spaces

* OutgoingHttpHeaders use generic type .map; rename flattenObject => objectEntries

* refactor: use build-in querystring

* break up v2/v4 signed url query interface

* add comments about the construction of canonical headers

* npm run fix

* git merge failed to put code in right place

* test: assert SigningError thrown

* test(v4): resumable upload

* prefer string.includes over indexOf

* npm run fix

* docs: add a note on POST and X-Goog-Resumable

* SEVEN_DAYS = 604800

* emit warning when using default version

* emitWarning if using default version for signing

* restore stub

* add new line

* test: v4 signed URL: conformance test (#638)

* Revert "split out conformance test"

This reverts commit ce00255.

* sync conformance-test cases; parse cases without modification

* this.skip

* refactor: lift interface

* remove default v2 warning

* docs(samples): Samples for v4 Signed URL (#654)

* remove timeout on conformance-test

* npm run fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement. 🚨 This issue needs some love.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants