-
Notifications
You must be signed in to change notification settings - Fork 814
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
Straightforwardly fixes a few minor copy bugs and adds a small fuzz util #5572
Merged
davidporter-id-au
merged 9 commits into
cadence-workflow:master
from
davidporter-id-au:bugfix/adding-some-missing-coverage-to-copy-utils
Mar 6, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
17ca5a4
Straightforwardly fixes a few minor copy bugs and adds a small fuzz util
davidporter-id-au 3e60b72
missing file
davidporter-id-au 1a7e403
fix
davidporter-id-au 3dd90d0
fmt
davidporter-id-au b9c024b
another small bugfix
davidporter-id-au 26f2797
Merge branch 'master' into bugfix/adding-some-missing-coverage-to-cop…
davidporter-id-au 96dc077
Adding
davidporter-id-au 64311a3
Adding the generator
davidporter-id-au c9461a5
Merge branch 'master' into bugfix/adding-some-missing-coverage-to-cop…
davidporter-id-au 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,38 @@ | ||
// The MIT License (MIT) | ||
|
||
// Copyright (c) 2017-2020 Uber Technologies Inc. | ||
|
||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
package testdatagen | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
fuzz "github.com/google/gofuzz" | ||
) | ||
|
||
// NewFuzzer creates a new fuzzer, notes down the deterministic seed | ||
func New(t *testing.T, generatorFuncs ...interface{}) *fuzz.Fuzzer { | ||
seed := time.Now().Unix() | ||
t.Log("Fuzz Seed:", seed) | ||
|
||
return fuzz.NewWithSeed(time.Now().Unix()).Funcs(generatorFuncs...).NilChance(0.2) | ||
} |
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,65 @@ | ||
// The MIT License (MIT) | ||
|
||
// Copyright (c) 2017-2020 Uber Technologies Inc. | ||
|
||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
package idlfuzzedtestdata | ||
|
||
import ( | ||
"testing" | ||
|
||
fuzz "github.com/google/gofuzz" | ||
|
||
"github.com/uber/cadence/common/testing/testdatagen" | ||
"github.com/uber/cadence/common/types" | ||
"github.com/uber/cadence/common/types/testdata" | ||
) | ||
|
||
// NewFuzzerWithIDLTypes creates a new fuzzer, notes down the deterministic seed | ||
// this particular invocation is preconfigured to be able to handle idl structs | ||
// correctly without generating completely invalid data (which, while good to test for | ||
// in the context of an application is too wide a search to be useful) | ||
func NewFuzzerWithIDLTypes(t *testing.T) *fuzz.Fuzzer { | ||
return testdatagen.New(t, | ||
// USE THESE VERY SPARINGLY, ONLY WHEN YOU MUST! | ||
// | ||
// The goal of providing these generators for specific types should be | ||
// to use them as little as possible, as they are fixed test data | ||
// which will not evolve with the idl or functions, therefore | ||
// the main benefit of fuzzing - evolving tests to handle all new fields in place - | ||
// will be defeated. | ||
// | ||
// for example, for mappers, if you add a new field that needs to be | ||
// mapped from protobuf to a native-go type (from the types folder) | ||
// and the testdata is fixed here *and not updated*, then the issue | ||
// will not be caught by any roundtrip tests. | ||
GenHistoryEvent, | ||
) | ||
} | ||
|
||
// GenHistoryEvent is a function to use with gofuzz which | ||
// skips the majority of difficult to generate values | ||
// for the sake of simplicity in testing. Use it with the fuzz.Funcs(...) generation function | ||
func GenHistoryEvent(o *types.HistoryEvent, c fuzz.Continue) { | ||
// todo (david.porter) setup an assertion to ensure this list is exhaustive | ||
i := c.Rand.Intn(len(testdata.HistoryEventArray) - 1) | ||
o = testdata.HistoryEventArray[i] | ||
return | ||
} |
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
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
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
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.
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.
bleh. I really need to try to finish a "this struct must be completely filled out" linter...
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.
linter or unit test?
one option could be to write tests using cmp.Diff and pass source object fully populated. to make it future proof, test can also validate all the public fields in the source object tree is non-nil.
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.
That's fundamentally what I'm looking to enable with the generator here - the filling out completely thing.
As Steven mentions, an alternative would be some kind of linter which checks for unfilled / nil substructs or subfields. I worry though that that's a somewhat more intrusive / homebrewed solution requiring some annotation thing we come up with.