Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@quiye
Copy link
Owner

@quiye quiye commented Oct 11, 2020

Added test is expeceted to fail by data overwriting.

@quiye
Copy link
Owner Author

quiye commented Oct 11, 2020

bd097a9 As expected, added test is failed. See the result of GitHub Actions.
a9d4e6e By avoiding to reuse response, test passed.

Copy link

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Great catch! Both the fix and the test look great 💖

loop:
for {
variables["limit"] = pageLimit
var response struct {
Copy link

Choose a reason for hiding this comment

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

To avoid redeclaring this struct completely in every loop iteration, do you think your approach would also work if this struct was defined as a type outside of a loop, and response was created inside a loop here as an instance of that type?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thank you for your review.

I think my approach works even if the type (struct) is defined outside the loop.
After response is defined in each loop and the data is parsed into response, issues share the array referenced by the response until the next loop, but when moving to the next loop, response goes out of scope and destructed. Therefore, the array is only referenced by issues, not the same array in the next loop.

So it's okay to declare the type (struct) outside the loop. It seems that the loop code is easier to read.

},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Copy link

Choose a reason for hiding this comment

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

Does this need to be a table-based test since it only contains a single test case?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Not necessary. I'll fix this.

@quiye
Copy link
Owner Author

quiye commented Oct 14, 2020

I made a Pull Request to original repository cli#2190
So I'm going to close.

@quiye quiye closed this Oct 14, 2020
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.

3 participants