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

Fix duplicate ndots:0, and improve validation #2212

Merged
merged 4 commits into from
Jun 29, 2018

Conversation

thaJeztah
Copy link
Member

Addresses moby/moby#37349

This PR has a couple of changes:

1. Remove redundant and faulty assert messages

The "message" argument in assert.Equal expects a format string; the current string was not that, resulting in an incorrect message being printed;

--- FAIL: TestDNSOptions (1.28s)
        Location:       service_common_test.go:92
	Error:  	Not equal: "ndots:5" (expected)
			        != "ndots:0" (actual)
	Messages:	The option must be ndots:5 instead:%!(EXTRA string=ndots:0)

This patch removes the message altogether, because assert.Equal already prints enough information to catch the error;

--- FAIL: TestDNSOptions (1.28s)
        Location:       service_common_test.go:92
	Error:  	Not equal: "ndots:5" (expected)
			        != "ndots:0" (actual)

2. do not ignore user-provided "ndots:0" option

This is the actual fix: ndots:0 is a valid DNS option; previously, ndots:0 was ignored, leading to the default (ndots:0) also being applied;

Before this change:

docker network create foo
docker run --rm --network foo --dns-opt ndots:0 alpine cat /etc/resolv.conf
nameserver 127.0.0.11
options ndots:0 ndots:0

After this change:

docker network create foo
docker run --rm --network foo --dns-opt ndots:0 alpine cat /etc/resolv.conf
nameserver 127.0.0.11
options ndots:0

3. improve error message for invalid ndots number

Just a minor enhancement; instead of printing the whole option, print the number only, because that's what the error-message is pointing at;

Before this change:

invalid number for ndots option ndots:foobar

After this change:

invalid number for ndots option: foobar

4. ndots: produce error on negative numbers

Prevent (e.g.) ndots:-1 being silently ignored

The "message" argument in assert.Equal expects a format
string; the current string was not that, resulting in an
incorrect message being printed;

    --- FAIL: TestDNSOptions (1.28s)
            Location:       service_common_test.go:92
    	Error:  	Not equal: "ndots:5" (expected)
    			        != "ndots:0" (actual)
    	Messages:	The option must be ndots:5 instead:%!(EXTRA string=ndots:0)

This patch removes the message altogether, because assert.Equal
already prints enough information to catch the error;

    --- FAIL: TestDNSOptions (1.28s)
            Location:       service_common_test.go:92
    	Error:  	Not equal: "ndots:5" (expected)
    			        != "ndots:0" (actual)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
`ndots:0` is a valid DNS option; previously, `ndots:0` was
ignored, leading to the default (`ndots:0`) also being applied;

Before this change:

    docker network create foo
    docker run --rm --network foo --dns-opt ndots:0 alpine cat /etc/resolv.conf
    nameserver 127.0.0.11
    options ndots:0 ndots:0

After this change:

    docker network create foo
    docker run --rm --network foo --dns-opt ndots:0 alpine cat /etc/resolv.conf
    nameserver 127.0.0.11
    options ndots:0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
instead of printing the whole option, print the _number_ only,
because that's what the error-message is pointing at;

Before this change:

    invalid number for ndots option ndots:foobar

After this change:

    invalid number for ndots option: foobar

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah
Copy link
Member Author

ping @fcrisciani @selansen PTAL

Copy link

@fcrisciani fcrisciani left a comment

Choose a reason for hiding this comment

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

LGTM

@selansen
Copy link
Collaborator

LGTM

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