-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
prototest: fix early return condition in AssertElementsMatch #17416
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ae61102
prototest: fix early return condition in AssertElementsMatch
rboyer 53b4dac
add easy early abort for mismatched lengths
rboyer f81a7fb
fix agent/grpc-external/services/resource/list_test.go TestList_Many
rboyer 1502a50
put this in the correct place
rboyer 8c5de23
switch this to the style of other resource packages
rboyer 2dd208e
fix this test
rboyer a660017
Update write in test to use resource service instead of directly to t…
analogue 446851f
remove this now
rboyer 6b3215b
Merge branch 'main' into fix-prototest-bug
rboyer 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 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package prototest | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type wrap struct { | ||
V int | ||
O string | ||
} | ||
|
||
func (w *wrap) String() string { | ||
return strconv.Itoa(w.V) | ||
} | ||
|
||
func (w *wrap) GoString() string { | ||
return w.String() | ||
} | ||
|
||
func TestDiffElements_noProtobufs(t *testing.T) { | ||
// NOTE: this test only tests non-protobuf slices initially | ||
|
||
type testcase struct { | ||
a, b []*wrap | ||
notSame bool | ||
} | ||
|
||
run := func(t *testing.T, tc testcase) { | ||
diff := diffElements(tc.a, tc.b) | ||
if tc.notSame { | ||
require.False(t, diff == "", "expected not to be the same") | ||
} else { | ||
require.True(t, diff == "", "expected to be the same") | ||
} | ||
} | ||
|
||
w := func(v int) *wrap { | ||
return &wrap{V: v} | ||
} | ||
|
||
cases := map[string]testcase{ | ||
"nil": {}, | ||
"empty": {a: []*wrap{}, b: []*wrap{}}, | ||
"nil and empty": {a: []*wrap{}, b: nil}, | ||
"ordered match": { | ||
a: []*wrap{w(1), w(22), w(303), w(43004), w(-5)}, | ||
b: []*wrap{w(1), w(22), w(303), w(43004), w(-5)}, | ||
}, | ||
"permuted match": { | ||
a: []*wrap{w(1), w(22), w(303), w(43004), w(-5)}, | ||
b: []*wrap{w(-5), w(43004), w(303), w(22), w(1)}, | ||
}, | ||
// no match | ||
"1 vs nil": { | ||
a: []*wrap{w(1)}, | ||
b: nil, | ||
notSame: true, | ||
}, | ||
"1 vs 2": { | ||
a: []*wrap{w(1)}, | ||
b: []*wrap{w(2)}, | ||
notSame: true, | ||
}, | ||
"1,2 vs 2,3": { | ||
a: []*wrap{w(1), w(2)}, | ||
b: []*wrap{w(2), w(3)}, | ||
notSame: true, | ||
}, | ||
"1,2 vs 1,2,3": { | ||
a: []*wrap{w(1), w(2)}, | ||
b: []*wrap{w(1), w(2), w(3)}, | ||
notSame: true, | ||
}, | ||
} | ||
|
||
allCases := make(map[string]testcase) | ||
for name, tc := range cases { | ||
allCases[name] = tc | ||
allCases[name+" (flipped)"] = testcase{ | ||
a: tc.b, | ||
b: tc.a, | ||
notSame: tc.notSame, | ||
} | ||
} | ||
|
||
for name, tc := range allCases { | ||
t.Run(name, func(t *testing.T) { | ||
run(t, tc) | ||
}) | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the bug.