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

provide and use compiled in test certs (only) in tests #757

Merged
merged 1 commit into from
Apr 23, 2015

Conversation

tbg
Copy link
Member

@tbg tbg commented Apr 22, 2015

this allows tests to run without external dependencies while avoiding compiled-in testdata in the main build.

@@ -28,7 +28,8 @@ import (
)

// This is just the mechanics of certs generation.
func TestGenerateCerts(t *testing.T) {
// TODO(tschottdorf) make this test use the actual file system.
func disabledTestGenerateCerts(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.

shouldn't this work is you call ResetReadFileFn?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, hence the todo. It's done now.

@tbg tbg force-pushed the tschottdorf/mock_certs branch 2 times, most recently from 757d725 to 8c927c7 Compare April 23, 2015 13:14
@@ -49,8 +48,8 @@ func (c cliTest) Run(line string) {
var args []string
args = append(args, a[0])
args = append(args, fmt.Sprintf("-addr=%s", c.ServingAddr()))
// Always load server certs. Not sure if this path is a good assumption though.
args = append(args, fmt.Sprintf("-certs=%s", security.EmbeddedPrefix+"test_certs"))
// Always load test certs. Not sure if this path is a good assumption though.
Copy link
Contributor

Choose a reason for hiding this comment

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

you can remove the part about the path, that was when I used ${GOPATH}/src/...

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

@tbg tbg force-pushed the tschottdorf/mock_certs branch from 8c927c7 to 7c928b2 Compare April 23, 2015 13:16
@tbg
Copy link
Member Author

tbg commented Apr 23, 2015

PTAL @mberhault

@tbg tbg changed the title WIP: compile in test certs only during tests, mock out file system acces... provide and use compiled in test certs (only) in tests Apr 23, 2015
@mberhault
Copy link
Contributor

LGTM. assuming no test runners were missed.

this allows tests to run without external dependencies,
while avoiding compiled-in testdata in the main build.
@tbg tbg force-pushed the tschottdorf/mock_certs branch from 7c928b2 to a022f35 Compare April 23, 2015 13:19
tbg added a commit that referenced this pull request Apr 23, 2015
provide and use compiled in test certs (only) in tests
@tbg tbg merged commit 50c98a5 into master Apr 23, 2015
@tbg tbg deleted the tschottdorf/mock_certs branch April 23, 2015 13:44
@@ -26,7 +26,7 @@ import (

// NewTestContext returns a rpc.Context for testing.
func NewTestContext(t *testing.T) *Context {
tlsConfig, err := security.LoadTLSConfigFromDir(security.EmbeddedPrefix + "test_certs")
tlsConfig, err := security.LoadTLSConfigFromDir("test_certs")
Copy link
Member

Choose a reason for hiding this comment

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

Instead of leaking this constant "test_certs" directory, why not just have another security method called: security.LoadTLSConfigForTests? Then in security:

func LoadTLSConfigForTests() (*TLSConfig, error) {
  return LoadTLSConfigFromDir("test_certs")
}

Copy link
Member

Choose a reason for hiding this comment

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

Or make it an exported constant in the security package.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm currently refactoring some of this with much fewer TLS setups. I'll move the test path to an exported const.

Copy link
Member Author

Choose a reason for hiding this comment

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

@mberhault is refactoring the stuff anyways, I'll wait for the dust to settle. What's more worrying is that we currently do compile in the test certs everywhere, because it's used in the rpc/testing package. Will change that though.

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