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

add a test for default-gen output #55

Closed

Conversation

caesarxuchao
Copy link
Member

@caesarxuchao caesarxuchao commented May 12, 2017

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 12, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@caesarxuchao
Copy link
Member Author

@mbohlool could you help review it? Thanks.

fi
@go build -o /tmp/$(TOOL)
@PKGS=$$(go list ./output_tests/... | paste -sd' '); \
/tmp/$(TOOL) --logtostderr --v=6 -i $$(echo $$PKGS | sed 's/ /,/g') -O zz_generated
Copy link
Contributor

Choose a reason for hiding this comment

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

so the paste command above is adding space between package names and sed here convert those spaces to comma, right? why not just use paste -sd','?

Copy link
Member Author

Choose a reason for hiding this comment

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

I copy-pasted it from https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/authorization/v1/types.go#L27. I can update both if you think it's necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

The link is referring to the wrong file? Anyway I think you can just fix it here if you like. It is not necessary though.

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -0,0 +1,22 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you want the generated file to be buildable? is the test only making sure that the output is what we expecting?

Copy link
Member Author

Choose a reason for hiding this comment

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

The travis builds the entire repo.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can try to change .travis but that's more nasty IMHO :)

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, I suggest you rename the expected file zz_generated.go to zz_generated.expected, add the name zz_generated.go to git_ignore of that folder, and do a diff zz_generated.expected zz_generated.go instead of git diff ....

@caesarxuchao caesarxuchao force-pushed the add-defaulter-gen-tests branch 2 times, most recently from 29bd77c to 483cca9 Compare May 15, 2017 23:55
@caesarxuchao
Copy link
Member Author

@mbohlool updated, ptal. Thanks!

@mbohlool
Copy link
Contributor

LGTM

@mbohlool
Copy link
Contributor

But it look like travis is still compiling it :( maybe remove the file after you checked the diff?

fi
@go build -o /tmp/$(TOOL)
/tmp/$(TOOL) --logtostderr --v=6 -i ./output_tests/wholepkg -O zz_generated
@if ! diff -q ./output_tests/wholepkg/zz_generated.expected ./output_tests/wholepkg/zz_generated.go; then \
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

The generated code depends on apimachinery so it does not compile and fails travis. So i changed the suffix to .expected.

Copy link
Member

Choose a reason for hiding this comment

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

Why does this exist? The library has a --verify-only option specifically so that we would not write things like this any more.

Copy link
Member Author

@caesarxuchao caesarxuchao May 17, 2017

Choose a reason for hiding this comment

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

We can change the default-gen Makefile to use --verify-only in a follow-up PR.

For this PR, because the generated code does not compile and breaks travis, i need to change the suffix of the output file to .expected, so the --verify-only approach doesn't work.

To use --verify-only, we have two options:

  • vendor a mock apimachinery folder in the test package to make the code compile.
  • hack the .travis to ignore this package.

@lavalamp please let me know how you want me to proceed. Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

blech wrt having external deps. OK. Can you comment that?

The point of checking it in is so that a human can look at a series of trivial output tests, and comprehend the output. --verify-only doesn't give me that?

}

// No defaulter will be generated
type Stuct_No_Field_Has_Manual_Defaulter struct {
Copy link
Member

Choose a reason for hiding this comment

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

s/Stuct/Struct/g

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@lavalamp
Copy link
Member

lavalamp commented May 18, 2017 via email

@thockin
Copy link
Member

thockin commented May 18, 2017 via email

@caesarxuchao
Copy link
Member Author

How about split to 'make all' and 'make verify'?

I still need to bypass the compile issue, how about the "vendor a mock apimachinery package" trick?

@mbohlool
Copy link
Contributor

mbohlool commented May 18, 2017

@thockin

In the deepcopy case, we regenerate and git diff which makes it easy for
people to produce the thing they need to check in.

I disagree with this strategy for tests. Being able to check in a different test output to pass the test make it easier for people to bypass tests and don't look at the change before checking in. When people forced to fix test cases manually it more likely for them to spot a problem vs just run the test and check in the diff. (I am arguing this only for test, for production generated code, easier to check in is better).

@caesarxuchao
Copy link
Member Author

@mbohlool i think it's fine as long as the difference of the generated code is shown in the PR and gets reviewed, so I agree with @thockin here.

@thockin How about split to 'make' to 'make all' and 'make verify', and use the '--verify-only' flag when run 'make verify'?

I still need to bypass the compile issue, how about the "vendor a mock apimachinery package" trick?

@thockin
Copy link
Member

thockin commented May 30, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants