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

sql: adds unit tests for schemaexpr.CheckConstraintBuilder #49777

Merged
merged 1 commit into from
Jun 2, 2020

Conversation

mgartner
Copy link
Collaborator

@mgartner mgartner commented Jun 1, 2020

This commit adds unit tests to the previously untested functions
of schemaexpra.CheckConstraintBuilder.DefaultName. It also adds a
testutils.go file to the schemaexpr package with a function that
makes it easier to create table descriptors that can be used in tests.

Release note: None

@mgartner mgartner requested a review from jordanlewis June 1, 2020 22:59
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@jordanlewis jordanlewis requested a review from rohany June 2, 2020 01:56
Copy link
Contributor

@rohany rohany left a comment

Choose a reason for hiding this comment

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

Some nits -- nice to see tests for all this random sql stuff!

pkg/sql/schemaexpr/check_constraint_test.go Outdated Show resolved Hide resolved
// TODO(mgartner);
}

func TestCheckConstraintBuilder_Build(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit]: Do we usually mix camel and snake case?

Copy link
Collaborator Author

@mgartner mgartner Jun 2, 2020

Choose a reason for hiding this comment

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

Haha good question. I have seen it elsewhere, and Goland suggested it. It looks not very common in cockroachdb, but there are a handful of examples, such as

func TestFuncDeps_ColsAreKey(t *testing.T) {

}
}

func TestCheckConstraintBuilder_DefaultName(t *testing.T) {
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 think this test is somewhat brittle? Or we aren't changing how we generate names for default columns in the future

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In my mind, a "brittle" test is one that breaks when the implementation details change but the API "contract" (in this case input/output) does not. I don't think this is brittle because it is guaranteeing a specific output based on a specific input, but doesn't assert how that output is generated.

If we did want to change this "contract" in the future (AFAIK we have no plans to) then updating the tests to guarantee the new contract seems like a valuable step to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see -- I wasn't sure there was a set contract on how the constraint names will be formatted.

@mgartner mgartner force-pushed the unit-test-schema-expr-build branch from aee60f9 to cc71a6b Compare June 2, 2020 16:37
@rohany
Copy link
Contributor

rohany commented Jun 2, 2020

LGTM

This commit adds unit tests to the previously untested functions
of `schemaexpra.CheckConstraintBuilder.DefaultName`. It also adds a
`testutils.go` file to the `schemaexpr` package with a function that
makes it easier to create table descriptors that can be used in tests.

Release note: None
@mgartner mgartner force-pushed the unit-test-schema-expr-build branch from cc71a6b to 516d593 Compare June 2, 2020 18:37
@mgartner
Copy link
Collaborator Author

mgartner commented Jun 2, 2020

bors r+

@craig
Copy link
Contributor

craig bot commented Jun 2, 2020

Build succeeded

@craig craig bot merged commit 31aa222 into cockroachdb:master Jun 2, 2020
@mgartner mgartner deleted the unit-test-schema-expr-build branch June 2, 2020 21:43
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.

3 participants