Skip to content

batches/executor: fix TestCreateChangesetSpecs#556

Merged
LawnGnome merged 1 commit into
mainfrom
aharvey/fix-test-ccs
Jun 16, 2021
Merged

batches/executor: fix TestCreateChangesetSpecs#556
LawnGnome merged 1 commit into
mainfrom
aharvey/fix-test-ccs

Conversation

@LawnGnome

Copy link
Copy Markdown
Contributor

The specWith() and taskWith() helpers inadvertently mutate defaultChangesetSpec and defaultTask fields, rather than isolating their changes to just the returned spec and task, respectively. Practically speaking, this means that all tests have the same spec and task based on the last element in the tests slice, which means that all the test cases end up testing the same, identical thing.

Instead, we must deep copy the spec and task before invoking the mutator function. I've chosen to pull in a third party package (specifically, copystructure) for this: naïvely using JSON to marshal and unmarshal doesn't work because most of the interesting task fields are excluded when marshalled to JSON.

The `specWith()` and `taskWith()` helpers inadvertently mutate
`defaultChangesetSpec` and `defaultTask` fields, rather than isolating
their changes to just the returned spec and task, respectively.
Practically speaking, this means that all tests have the same spec and
task based on the last element in the `tests` slice, which means that
all the test cases end up testing the same, identical thing.

Instead, we must deep copy the spec and task before invoking the mutator
function. I've chosen to pull in a third party package (specifically,
copystructure) for this: naïvely using JSON to marshal and unmarshal
doesn't work because most of the interesting task fields are excluded
when marshalled to JSON.
@LawnGnome LawnGnome requested a review from a team June 15, 2021 23:11
@LawnGnome LawnGnome self-assigned this Jun 15, 2021

@chrispine chrispine left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@LawnGnome LawnGnome merged commit 228eff0 into main Jun 16, 2021
@LawnGnome LawnGnome deleted the aharvey/fix-test-ccs branch June 16, 2021 22:40
scjohns pushed a commit that referenced this pull request Apr 24, 2023
The `specWith()` and `taskWith()` helpers inadvertently mutate
`defaultChangesetSpec` and `defaultTask` fields, rather than isolating
their changes to just the returned spec and task, respectively.
Practically speaking, this means that all tests have the same spec and
task based on the last element in the `tests` slice, which means that
all the test cases end up testing the same, identical thing.

Instead, we must deep copy the spec and task before invoking the mutator
function. I've chosen to pull in a third party package (specifically,
copystructure) for this: naïvely using JSON to marshal and unmarshal
doesn't work because most of the interesting task fields are excluded
when marshalled to JSON.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants