-
Notifications
You must be signed in to change notification settings - Fork 2
Promote find mmr entries and find trie entries to non IKWID commands #48
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
Open
honourfish
wants to merge
4
commits into
main
Choose a base branch
from
dev/jgough/10376-promote-find-cmds
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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,226 @@ | ||
| package findmmrentries | ||
|
|
||
| import ( | ||
| "io" | ||
| "os" | ||
| "strings" | ||
|
|
||
| "github.com/datatrails/veracity" | ||
| "github.com/datatrails/veracity/tests/katdata" | ||
| ) | ||
|
|
||
| const ( | ||
| prodPublicTenant = "tenant/6ea5cd00-c711-3649-6914-7b125928bbb4" | ||
| prodEventsv1Tenant = "tenant/97e90a09-8c56-40df-a4de-42fde462ef6f" | ||
| ) | ||
|
|
||
| // TestAssetsV2EventStdIn tests we can find | ||
| // the correct PROD public assetsv2 event mmr entry match | ||
| func (s *FindMMREntriesSuite) TestAssetsV2EventStdIn() { | ||
| assert := s.Assert() | ||
| require := s.Require() | ||
|
|
||
| app := veracity.NewApp("version", true) | ||
| veracity.AddCommands(app, true) | ||
|
|
||
| // note: the suite does a before & after pipe for Stdin | ||
| s.StdinWriteAndClose(katdata.KnownGoodPublicAssetsV2EventLaterMassif) | ||
|
|
||
| // redirect std out to a known pipe so we can capture it | ||
| rescueStdout := os.Stdout | ||
| defer func() { os.Stdout = rescueStdout }() // ensure we redirect std out back after | ||
|
|
||
| reader, writer, _ := os.Pipe() | ||
| os.Stdout = writer | ||
|
|
||
| err := app.Run([]string{ | ||
| "veracity", | ||
| "find-mmr-entries", | ||
| "--log-tenant", prodPublicTenant, | ||
| }) | ||
| assert.NoErrorf(err, "the event is a known good event from the public production tenant, yet we have errored trying to find the mmr entries") | ||
|
|
||
| writer.Close() | ||
| actualBytes, err := io.ReadAll(reader) | ||
| require.NoError(err) | ||
|
|
||
| // convert the stdout to a string and strip the newlines | ||
| actual := strings.ReplaceAll(string(actualBytes), "\n", "") | ||
|
|
||
| assert.Equal("matches: [27899]", actual) | ||
| } | ||
|
|
||
| // TestAssetsV2EventAsLeafIndexStdIn tests we can find | ||
| // the correct PROD public assetsv2 event mmr entry match as | ||
| // a leaf index. | ||
| func (s *FindMMREntriesSuite) TestAssetsV2EventAsLeafIndexStdIn() { | ||
| assert := s.Assert() | ||
| require := s.Require() | ||
|
|
||
| app := veracity.NewApp("version", true) | ||
| veracity.AddCommands(app, true) | ||
|
|
||
| // note: the suite does a before & after pipe for Stdin | ||
| s.StdinWriteAndClose(katdata.KnownGoodPublicAssetsV2EventLaterMassif) | ||
|
|
||
| // redirect std out to a known pipe so we can capture it | ||
| rescueStdout := os.Stdout | ||
| defer func() { os.Stdout = rescueStdout }() // ensure we redirect std out back after | ||
|
|
||
| reader, writer, _ := os.Pipe() | ||
| os.Stdout = writer | ||
|
|
||
| err := app.Run([]string{ | ||
| "veracity", | ||
| "find-mmr-entries", | ||
| "--log-tenant", prodPublicTenant, | ||
| "--massif-start", "1", | ||
| "--massif-end", "1", // the event is in massif 1 | ||
| "--as-leafindexes", "true", | ||
| }) | ||
| assert.NoErrorf(err, "the event is a known good event from the public production tenant, yet we have errored trying to find the mmr entries") | ||
|
|
||
| writer.Close() | ||
| actualBytes, err := io.ReadAll(reader) | ||
| require.NoError(err) | ||
|
|
||
| // convert the stdout to a string and strip the newlines | ||
| actual := strings.ReplaceAll(string(actualBytes), "\n", "") | ||
|
|
||
| assert.Equal("matches: [13952]", actual) | ||
| } | ||
|
|
||
| // TestAssetsV2EventWrongMassifStdIn tests we CANNOT find | ||
| // the correct PROD public assetsv2 event mmr entry match | ||
| // if we set the range of massifs to not include the massif the event is in. | ||
| func (s *FindMMREntriesSuite) TestAssetsV2EventWrongMassifStdIn() { | ||
| assert := s.Assert() | ||
| require := s.Require() | ||
|
|
||
| app := veracity.NewApp("version", true) | ||
| veracity.AddCommands(app, true) | ||
|
|
||
| // note: the suite does a before & after pipe for Stdin | ||
| s.StdinWriteAndClose(katdata.KnownGoodPublicAssetsV2EventLaterMassif) | ||
|
|
||
| // redirect std out to a known pipe so we can capture it | ||
| rescueStdout := os.Stdout | ||
| defer func() { os.Stdout = rescueStdout }() // ensure we redirect std out back after | ||
|
|
||
| reader, writer, _ := os.Pipe() | ||
| os.Stdout = writer | ||
|
|
||
| err := app.Run([]string{ | ||
| "veracity", | ||
| "find-mmr-entries", | ||
| "--log-tenant", prodPublicTenant, | ||
| "--massif-start", "0", | ||
| "--massif-end", "0", // the actual event is in massif 1 | ||
| }) | ||
| assert.NoErrorf(err, "the event is a known good event from the public production tenant, yet we have errored trying to find the mmr entries") | ||
|
|
||
| writer.Close() | ||
| actualBytes, err := io.ReadAll(reader) | ||
| require.NoError(err) | ||
|
|
||
| // convert the stdout to a string and strip the newlines | ||
| actual := strings.ReplaceAll(string(actualBytes), "\n", "") | ||
|
|
||
| assert.Equal("matches: []", actual) | ||
| } | ||
|
|
||
| // TestAssetsV2EventCorrectMassifStdIn tests we CAN find | ||
| // the correct PROD public assetsv2 event mmr entry match | ||
| // if we set the range of massifs to include ONLY the massif the event is in. | ||
| func (s *FindMMREntriesSuite) TestAssetsV2EventCorrectMassifStdIn() { | ||
| assert := s.Assert() | ||
| require := s.Require() | ||
|
|
||
| app := veracity.NewApp("version", true) | ||
| veracity.AddCommands(app, true) | ||
|
|
||
| // note: the suite does a before & after pipe for Stdin | ||
| s.StdinWriteAndClose(katdata.KnownGoodPublicAssetsV2EventLaterMassif) | ||
|
|
||
| // redirect std out to a known pipe so we can capture it | ||
| rescueStdout := os.Stdout | ||
| defer func() { os.Stdout = rescueStdout }() // ensure we redirect std out back after | ||
|
|
||
| rescueStderr := os.Stderr | ||
| defer func() { os.Stderr = rescueStderr }() // ensure we redirect std err back after | ||
|
|
||
| readerStdOut, writerStdOut, _ := os.Pipe() | ||
| os.Stdout = writerStdOut | ||
|
|
||
| readerStdErr, writerStdErr, _ := os.Pipe() | ||
| os.Stderr = writerStdErr | ||
|
|
||
| err := app.Run([]string{ | ||
| "veracity", | ||
| "--loglevel", "DEBUG", | ||
| "find-mmr-entries", | ||
| "--log-tenant", prodPublicTenant, | ||
| "--massif-start", "1", | ||
| "--massif-end", "1", // the actual event is in massif 1 | ||
| }) | ||
| assert.NoErrorf(err, "the event is a known good event from the public production tenant, yet we have errored trying to find the mmr entries") | ||
|
|
||
| writerStdOut.Close() | ||
| actualStdOutBytes, err := io.ReadAll(readerStdOut) | ||
| require.NoError(err) | ||
|
|
||
| writerStdErr.Close() | ||
| actualStdErrBytes, err := io.ReadAll(readerStdErr) | ||
| require.NoError(err) | ||
|
|
||
| // convert the stdout to string and string new lines and convert stderr to string | ||
| actualStdOut := strings.ReplaceAll(string(actualStdOutBytes), "\n", "") | ||
| actualStdErr := string(actualStdErrBytes) | ||
|
|
||
| // assert we are checking the correct massif | ||
| assert.Contains(actualStdErr, "mmr entries in massif 1 for matches") | ||
|
|
||
| // assert we are not checking the neighbouring massifs | ||
| assert.NotContains(actualStdErr, "mmr entries in massif 0 for matches") | ||
| assert.NotContains(actualStdErr, "mmr entries in massif 2 for matches") | ||
|
|
||
| assert.Equal("matches: [27899]", actualStdOut) | ||
| } | ||
|
|
||
| // TestEventsV1EventRepeatedAppDataStdIn tests we can find | ||
| // the correct PROD eventsv1 event mmr entry matches for app data used | ||
| // for 2 events on the same log tenant. | ||
| func (s *FindMMREntriesSuite) TestEventsV1EventRepeatedAppDataStdIn() { | ||
| assert := s.Assert() | ||
| require := s.Require() | ||
|
|
||
| app := veracity.NewApp("version", true) | ||
| veracity.AddCommands(app, true) | ||
|
|
||
| // note: the suite does a before & after pipe for Stdin | ||
| s.StdinWriteAndClose(katdata.KnownGoodEventsv1RepeatedAppData) | ||
|
|
||
| // redirect std out to a known pipe so we can capture it | ||
| rescueStdout := os.Stdout | ||
| defer func() { os.Stdout = rescueStdout }() // ensure we redirect std out back after | ||
|
|
||
| reader, writer, _ := os.Pipe() | ||
| os.Stdout = writer | ||
|
|
||
| err := app.Run([]string{ | ||
| "veracity", | ||
| "find-mmr-entries", | ||
| "--log-tenant", prodEventsv1Tenant, | ||
| }) | ||
| assert.NoErrorf(err, "the event is a known good event from the production tenant we are using for test eventsv1 events, yet we have errored trying to find the mmr entries") | ||
|
|
||
| writer.Close() | ||
| actualBytes, err := io.ReadAll(reader) | ||
| require.NoError(err) | ||
|
|
||
| // convert the stdout to a string and strip the newlines | ||
| actual := strings.ReplaceAll(string(actualBytes), "\n", "") | ||
|
|
||
| // check we get back matches mmr indexes 26 and 31 | ||
| assert.Equal("matches: [26 31]", actual) | ||
| } | ||
This file contains hidden or 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,18 @@ | ||
| package findmmrentries | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/datatrails/veracity/tests" | ||
| "github.com/stretchr/testify/suite" | ||
| ) | ||
|
|
||
| // FindMMREntriesSuite deals with tests around finding mmr entries | ||
| type FindMMREntriesSuite struct { | ||
| tests.IntegrationTestSuite | ||
| } | ||
|
|
||
| func TestFindMMREntriesSuite(t *testing.T) { | ||
|
|
||
| suite.Run(t, new(FindMMREntriesSuite)) | ||
| } |
Oops, something went wrong.
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.
I like this test, But setting the range to be zero length will likely excersise the short circute do nothing path. Just take this as a minor comment, I think these tests are great. Its hard to be sure we have enough massifs to do a non zero scan that ommits the massif containing the event
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.
I agree, we need to ramp up the public events :P I will revist the test when we have a later massifs in the prod public tenant.
It doesn't short circuit, it considers the first massif only (index 0) and there are two massifs
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.
although i agree that this test won't catch a short circuit if its introduced at a later date, so its not really a regression test for short circuiting at the 0 massif