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

V2: WIP: Tests for Replacer #2675

Merged
merged 18 commits into from
Jul 21, 2019
Merged

V2: WIP: Tests for Replacer #2675

merged 18 commits into from
Jul 21, 2019

Conversation

aligator
Copy link
Contributor


name: Tests for Replacer
about: Testing the Replacer

1. What does this change do, exactly?

This PR adds tests for the Replacer.

Currently there are tests for Set and Delete. (Both use ReplaceAll to check if they work, but I also want to write an extra test for it.)

Question: Should I test only through the Interface or the replacer type directly?

2. Please link to the relevant issues.

#2673
#2674

3. Which documentation changes (if any) need to be made because of this PR?

--

4. Checklist

  • I have squashed any insignificant commits
  • This change has comments explaining package types, values, functions, and non-obvious lines of code
  • I am willing to help maintain this change if there are issues with it later

@CLAassistant
Copy link

CLAassistant commented Jul 16, 2019

CLA assistant check
All committers have signed the CLA.

@aligator aligator changed the title WIP: Tests for Replacer V2: WIP: Tests for Replacer Jul 17, 2019
@aligator
Copy link
Contributor Author

aligator commented Jul 17, 2019

Just noticed that I based the test on the old implementation. Updated it now to the new one (just used string(phOpen) instead of phOpen) and...
the tests fail:
replacer_test.go:81: Expectd 'val1123098765öö_äüspace valuetest-1231.2.3.4EMPTY{MyNotSetVariable}', got 'val1{asdf}098765{23456789}space value{1}1.2.3.4{testEmpty}{testEmpty}{MyNotSetVariable}' for input '{test1}{asdf}{äöü}{23456789}{with space}{1}{mySuper_IP}{testEmpty}{MyNotSetVariable}'

Seems that it always missed one, because my test string has no spaces between the } and {. This worked with your previous implementation.

Fix is in this branch https://github.com/aligator/caddy/tree/v2-fix-replacer but there seems to be at least one other bug because the second test fails even with the fix.

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.

Nice start! I like that you're using table-driven tests.

Question: Should I test only through the Interface or the replacer type directly?

I would test the concrete replacer type, since in the tests we actually care about the implementation.

Here are a few ideas for things we need to test:

In unit tests, don't call ReplaceAll when what you are testing is Set or Delete or anything other than ReplaceAll. Instead, to test Set, call Set() and then check the static map to ensure the value was set.

@mholt mholt added the v2 label Jul 17, 2019
@aligator
Copy link
Contributor Author

Ok, thank you for your suggestions. I will update my tests accordingly.

I just added one for something like {l{test1}...
This test fails with my current fixes in my fix-branch.

@mholt
Copy link
Member

mholt commented Jul 17, 2019

I just added one for something like {l{test1}...
This test fails with my current fixes in my fix-branch.

Excellent. :) That doesn't surprise me. You can either propose a fix in this PR or I can commit a fix. I'll be happy with either option.

@aligator
Copy link
Contributor Author

@mholt could you please review this? I rewrote the tests and added new ones. Also I included two little fixes for the replacer logic.

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.

Thanks for the updates! Looking much better.

replacer_test.go Outdated Show resolved Hide resolved
replacer_test.go Outdated Show resolved Hide resolved
replacer_test.go Outdated Show resolved Hide resolved
replacer_test.go Outdated Show resolved Hide resolved
replacer_test.go Outdated Show resolved Hide resolved
replacer_test.go Outdated Show resolved Hide resolved
replacer_test.go Outdated Show resolved Hide resolved
replacer.go Show resolved Hide resolved
replacer.go Show resolved Hide resolved
},
{
variable: "äöü",
value: "öö_äü",
Copy link
Member

Choose a reason for hiding this comment

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

Good thinking to test unicode

aligator added 2 commits July 20, 2019 12:42
as new should return a replace with provider which defines global replacements
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.

LGTM. Are you ready for this to be merged?

@aligator
Copy link
Contributor Author

Yes, you can merge this.

@mholt mholt merged commit 95a447d into caddyserver:v2 Jul 21, 2019
@mholt
Copy link
Member

mholt commented Jul 21, 2019

Thanks for your contribution! It's nice to have that under some testing.

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.

None yet

3 participants