Skip to content
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

Refactor get_tree_public_key test helper methods #1247

Merged
merged 3 commits into from Aug 7, 2018

Conversation

maljub01
Copy link
Contributor

@maljub01 maljub01 commented Aug 2, 2018

  • Move setFlag to setup.SetFlag.
  • Remove CreateLog in favor of using the existing CreateAndInitTree.

Moves `setFlag` and `createLog` to `setup.SetFlag` and
`setup.CreateLog`, which would make it easier to reuse those helpers in
other tests as well.
@codecov
Copy link

codecov bot commented Aug 2, 2018

Codecov Report

Merging #1247 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1247   +/-   ##
======================================
  Coverage    58.1%   58.1%           
======================================
  Files         113     113           
  Lines        9573    9573           
======================================
  Hits         5562    5562           
  Misses       3439    3439           
  Partials      572     572

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cc0e4fa...fa03d29. Read the comment docs.

)

// SetFlag updates a flag value, failing the test if something goes wrong.
func SetFlag(t *testing.T, name, value string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to revert the flag after the test is finished?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverting is done in bulk using defer flagsaver.Save().Restore()

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks

"github.com/golang/protobuf/ptypes"
"github.com/google/trillian"
"github.com/google/trillian/client"
ktestonly "github.com/google/trillian/crypto/keys/testonly"

This comment was marked as resolved.

//
// It optionally allows specifying an overrides argument to override some
// properties of the tree to be created.
func CreateLog(t *testing.T, logEnv *integration.LogEnv, maxRootDuration time.Duration) *trillian.Tree {

This comment was marked as resolved.

func CreateLog(t *testing.T, logEnv *integration.LogEnv, maxRootDuration time.Duration) *trillian.Tree {
t.Helper()

ctx := context.Background()

This comment was marked as resolved.

//
// It optionally allows specifying an overrides argument to override some
// properties of the tree to be created.
func CreateLog(t *testing.T, logEnv *integration.LogEnv, maxRootDuration time.Duration) *trillian.Tree {

This comment was marked as resolved.

@gdbelvin gdbelvin self-requested a review August 6, 2018 13:31
Copy link
Contributor

@gdbelvin gdbelvin left a comment

Choose a reason for hiding this comment

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

It looks like the test helpers are fairly test specific.

Consider moving the test helper functions into the test files themselves. See the map_test's
newTreeWithHasher helper function.

@maljub01
Copy link
Contributor Author

maljub01 commented Aug 6, 2018

The reason I'm putting those helper functions in a separate module is that I want to use them in multiple test files. They are currently being used in cmd/get_tree_public_key/main_test.go, but I would also like to create a logmonitor command and will need those same helpers for its main_test.go as well.

// It requires the caller to specify a maxRootDuration for the Trillian tree,
// which will be used as the interval after which a new signed root is produced
// despite no submissions.
func CreateLog(ctx context.Context, t *testing.T, logClient trillian.TrillianLogClient, adminClient trillian.TrillianAdminClient, maxRootDuration time.Duration) *trillian.Tree {

This comment was marked as outdated.

// It requires the caller to specify a maxRootDuration for the Trillian tree,
// which will be used as the interval after which a new signed root is produced
// despite no submissions.
func CreateLog(ctx context.Context, t *testing.T, logClient trillian.TrillianLogClient, adminClient trillian.TrillianAdminClient, maxRootDuration time.Duration) *trillian.Tree {
Copy link
Contributor

Choose a reason for hiding this comment

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

Existing tests call CreateAndInitTree directly. Please follow that convention in your tests.
Example

It looks like the main utility of this function is a helper for creating a trillian.Tree.
a) There are some convenient, prepopulated test trees that you can use, copy, and modify in your tests.
b) If you prefer, this function could be reduced to CreateTreeRequest with a suite of With* modifiers.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't know about CreateAndInitTree. I'll switch to using it.

Thank you.

@gdbelvin
Copy link
Contributor

gdbelvin commented Aug 6, 2018

It looks like there's an easier way to get test trees setup. What do you think about using that approach? We'd prefer to reduce code duplication.

@maljub01
Copy link
Contributor Author

maljub01 commented Aug 6, 2018

Switched to using CreateAndInitTree and the tests are much better now! Thank you!

@maljub01 maljub01 changed the title Move get_tree_public_key test helper methods to a common place Refactor get_tree_public_key test helper methods Aug 6, 2018
Copy link
Contributor

@gdbelvin gdbelvin left a comment

Choose a reason for hiding this comment

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

LGTM

@maljub01
Copy link
Contributor Author

maljub01 commented Aug 7, 2018

Thanks for the review.

All checks have passed, but I don't have the write permissions needed to merge this.

@gdbelvin gdbelvin merged commit 8515c71 into google:master Aug 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants