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

caddytest: internalize init config into '.go' file #5230

Merged
merged 2 commits into from
Dec 5, 2022

Conversation

mohammed90
Copy link
Member

Go module distribution excludes files that are not of a specific list of types. In other words,.go files are retained in the downloaded modules, but others are not for sure1. This causes pain, e.g. #5187. The workaround in this PR is to write the init config to a temp file, and set the cleanup func to delete the file at the end of the test run.

For the record, I tried passing the init config t oos.Stdin by creating a os.Pipe, writing to the writer end, and setting os.Stdin = reader. However, this seems to slow down the run to the extent of test timeouts. It did work sometimes when the timeout value is set for very long period. It's probably a race condition. I don't believe forcefully going down that route is worth it. Writing the init config to a temp file is much simpler and easier to maintain, unless I'm blind to some aspect.

Updates #5187

Footnotes

  1. I couldn't find a definite list of excluded files. If any knows of a reference, please share it!

@mohammed90
Copy link
Member Author

@greenpau can you check this PR by depending on the branch robust-integration-test?

@greenpau
Copy link

greenpau commented Dec 3, 2022

can you check this PR by depending on the branch robust-integration-test?

@mohammed90 , thank you for looking into it.

Added the following to go.mod:

replace github.com/caddyserver/caddy/v2 v2.6.2 => github.com/caddyserver/caddy/v2 v2.6.3-0.20221202133426-861c5c8268b7

Ran:

make test

I could see the test itself succeeds, b/c it gets to lines 59-60. https://github.com/greenpau/caddy-security/blob/cfc03c5f47313f4b2d6699193659f41040511b49/app_test.go#L59-L60

    app_test.go:59: &{200 OK 200 HTTP/2.0 2 0 map[Alt-Svc:[h3=":8443"; ma=2592000] Content-Length:[5] Content-Type:[text/plain; charset=utf-8] Date:[Sat, 03 Dec 2022 18:22:52 GMT] Server:[Caddy]] 0xc0002a1d20 5 [] false false map[] 0xc000d63600 0xc001158630}
    app_test.go:60: 1.0.0
    caddytest.go:128: unable to read the current config

But then caddytest.go throws an error:

caddytest.go:128: unable to read the current config

The config I am using is here https://github.com/greenpau/caddy-security/blob/cfc03c5f47313f4b2d6699193659f41040511b49/assets/config/Caddyfile

@mohammed90
Copy link
Member Author

can you check this PR by depending on the branch robust-integration-test?

@mohammed90 , thank you for looking into it.

Added the following to go.mod:

replace github.com/caddyserver/caddy/v2 v2.6.2 => github.com/caddyserver/caddy/v2 v2.6.3-0.20221202133426-861c5c8268b7

Ran:

make test

I could see the test itself succeeds, b/c it gets to lines 59-60. https://github.com/greenpau/caddy-security/blob/cfc03c5f47313f4b2d6699193659f41040511b49/app_test.go#L59-L60

    app_test.go:59: &{200 OK 200 HTTP/2.0 2 0 map[Alt-Svc:[h3=":8443"; ma=2592000] Content-Length:[5] Content-Type:[text/plain; charset=utf-8] Date:[Sat, 03 Dec 2022 18:22:52 GMT] Server:[Caddy]] 0xc0002a1d20 5 [] false false map[] 0xc000d63600 0xc001158630}
    app_test.go:60: 1.0.0
    caddytest.go:128: unable to read the current config

But then caddytest.go throws an error:

caddytest.go:128: unable to read the current config

The config I am using is here https://github.com/greenpau/caddy-security/blob/cfc03c5f47313f4b2d6699193659f41040511b49/assets/config/Caddyfile

Your Caddyfile overrides the admin address, changing it from 2999 on first POST to 2019. That issue did occur to me, but I didn't figure out a solution to how to inject the correct admin port in client config. For now, just include admin localhost:2999 in your global options.

@greenpau
Copy link

greenpau commented Dec 3, 2022

Your Caddyfile overrides the admin address, changing it from 2999 on first POST to 2019. That issue did occur to me, but I didn't figure out a solution to how to inject the correct admin port in client config. For now, just include admin localhost:2999 in your global options.

added admin localhost:2999 to global options.

@mohammed90 , the test passes now! 👍

Copy link
Collaborator

@sarge sarge left a comment

Choose a reason for hiding this comment

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

Great find! @mohammed90

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Thank you @mohammed90, nice workaround!

@mohammed90 mohammed90 merged commit fef9cb3 into master Dec 5, 2022
@mohammed90 mohammed90 deleted the robust-integration-test branch December 5, 2022 18:49
@francislavoie francislavoie added this to the v2.6.3 milestone Dec 6, 2022
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.

5 participants