Skip to content

cli: add framework for writing dump tests#22403

Closed
justinj wants to merge 1 commit intocockroachdb:masterfrom
justinj:dump-test-file
Closed

cli: add framework for writing dump tests#22403
justinj wants to merge 1 commit intocockroachdb:masterfrom
justinj:dump-test-file

Conversation

@justinj
Copy link
Copy Markdown
Contributor

@justinj justinj commented Feb 6, 2018

I quite frequently find myself having to add new tests and functionality
to dump. While the existing setup for writing tests was quite good, and
easy to add new tests, I often found myself wanting to be able to
rewrite-results-in-testfiles it (especially due to whitespace issues),
and not write my tests in a string literal, so my attempt at changing
this is a somewhat radical one - a logic test-esque file format that's
composed of a schema and an expected dump output.

Feel free to reject this PR for any of the following reasons, my
feelings won't be hurt:

  • not worth the review or engineering effort this close to code freeze
  • not worth the review or engineering effort period
  • not a fan of the approach in general

This PR is still missing a number of things, however:

  • I haven't ported over all of the existing dump tests
  • error handling when writing a faulty test file could be better
  • bikeshedding about the syntax
  • code could be cleaned up a bit, not too interested in discussion on
    that at this point, more interested in thoughts on the general approach.

I think this general format of

  • parameters incl. test name
  • input
  • output

could be quite useful in general and we might be able to extract some
kind of general framework for it in the future if we decide to go that
route.

@justinj justinj requested a review from a team as a code owner February 6, 2018 04:53
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor

@madelynnblue madelynnblue left a comment

Choose a reason for hiding this comment

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

I love this. One change I want to see first: after running the dump command, re-run it with -e and dump it again and verify that both dumps are the same. This is important to make sure things roundtrip correctly, which will detect problems in the dump output itself, which we've had before, for example when table names weren't correctly escaped.

Copy link
Copy Markdown
Member

@jordanlewis jordanlewis left a comment

Choose a reason for hiding this comment

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

Great idea! I'm into it.


% name reference_cycle
% command dump d t
-- This tests dumping in the presence of cycles. This used to crash before
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would suggest using # instead of -- for comments, like we do in the logic tests.

@justinj
Copy link
Copy Markdown
Contributor Author

justinj commented Feb 8, 2018

(I haven't forgotten about this PR, just have more time-sensitive things to handle at the moment, I will come back to it)

I quite frequently find myself having to add new tests and functionality
to dump. While the existing setup for writing tests was quite good, and
easy to add new tests, I often found myself wanting to be able to
`rewrite-results-in-testfiles` it (especially due to whitespace issues),
and not write my tests in a string literal, so my attempt at changing
this is a somewhat radical one - a logic test-esque file format that's
composed of a schema and an expected dump output.

I think this general format of

* parameters incl. test name
* input
* output

could be quite useful in general and we might be able to extract some
kind of general framework for it in the future if we decide to go that
route.

Release note: None.
@justinj justinj changed the title wip: add framework for writing dump tests cli: add framework for writing dump tests Feb 10, 2018
@justinj
Copy link
Copy Markdown
Contributor Author

justinj commented Feb 10, 2018

Ok, I think this is ready for another look! (Again, feel free to ignore if you're time-pressured at the moment, this is the opposite of time-sensitive)


Review status: 0 of 2 files reviewed at latest revision, 1 unresolved discussion, some commit checks pending.


pkg/cli/testdata/dump_test, line 46 at r1 (raw file):

Previously, jordanlewis (Jordan Lewis) wrote…

I would suggest using # instead of -- for comments, like we do in the logic tests.

Done, though I'm kind of torn here, it is more consistent than our logic tests, but the character # is sort of difficult to distinguish from %, and using -- makes comments work with SQL syntax highlighting.


Comments from Reviewable

@vilterp
Copy link
Copy Markdown
Contributor

vilterp commented Feb 13, 2018

Looks awesome; will review more when I have time (probably after code freeze).

@justinj
Copy link
Copy Markdown
Contributor Author

justinj commented Apr 11, 2018

superseded by #24653

@justinj justinj closed this Apr 11, 2018
@justinj justinj deleted the dump-test-file branch April 11, 2018 14:31
craig bot pushed a commit that referenced this pull request Apr 12, 2018
24653: cli: refactor dump tests to use datadriven r=mjibson a=mjibson

Idea from @justinj.

Closes #22403

Release note: None

Co-authored-by: Matt Jibson <matt.jibson@gmail.com>
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.

6 participants