-
Notifications
You must be signed in to change notification settings - Fork 509
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
Permit '=' separator and '[ipv6]' in --add-host #2121
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package build | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestToBuildkitExtraHosts(t *testing.T) { | ||
tests := []struct { | ||
doc string | ||
input []string | ||
expectedOut string // Expect output==input if not set. | ||
expectedErr string // Expect success if not set. | ||
}{ | ||
{ | ||
doc: "IPv4, colon sep", | ||
input: []string{`myhost:192.168.0.1`}, | ||
expectedOut: `myhost=192.168.0.1`, | ||
}, | ||
{ | ||
doc: "IPv4, eq sep", | ||
input: []string{`myhost=192.168.0.1`}, | ||
}, | ||
{ | ||
doc: "Weird but permitted, IPv4 with brackets", | ||
input: []string{`myhost=[192.168.0.1]`}, | ||
expectedOut: `myhost=192.168.0.1`, | ||
}, | ||
{ | ||
doc: "Host and domain", | ||
input: []string{`host.and.domain.invalid:10.0.2.1`}, | ||
expectedOut: `host.and.domain.invalid=10.0.2.1`, | ||
}, | ||
{ | ||
doc: "IPv6, colon sep", | ||
input: []string{`anipv6host:2003:ab34:e::1`}, | ||
expectedOut: `anipv6host=2003:ab34:e::1`, | ||
}, | ||
{ | ||
doc: "IPv6, colon sep, brackets", | ||
input: []string{`anipv6host:[2003:ab34:e::1]`}, | ||
expectedOut: `anipv6host=2003:ab34:e::1`, | ||
}, | ||
{ | ||
doc: "IPv6, eq sep, brackets", | ||
input: []string{`anipv6host=[2003:ab34:e::1]`}, | ||
expectedOut: `anipv6host=2003:ab34:e::1`, | ||
}, | ||
{ | ||
doc: "IPv6 localhost, colon sep", | ||
input: []string{`ipv6local:::1`}, | ||
expectedOut: `ipv6local=::1`, | ||
}, | ||
{ | ||
doc: "IPv6 localhost, eq sep", | ||
input: []string{`ipv6local=::1`}, | ||
}, | ||
{ | ||
doc: "IPv6 localhost, eq sep, brackets", | ||
input: []string{`ipv6local=[::1]`}, | ||
expectedOut: `ipv6local=::1`, | ||
}, | ||
{ | ||
doc: "IPv6 localhost, non-canonical, colon sep", | ||
input: []string{`ipv6local:0:0:0:0:0:0:0:1`}, | ||
expectedOut: `ipv6local=0:0:0:0:0:0:0:1`, | ||
}, | ||
{ | ||
doc: "IPv6 localhost, non-canonical, eq sep", | ||
input: []string{`ipv6local=0:0:0:0:0:0:0:1`}, | ||
}, | ||
{ | ||
doc: "IPv6 localhost, non-canonical, eq sep, brackets", | ||
input: []string{`ipv6local=[0:0:0:0:0:0:0:1]`}, | ||
expectedOut: `ipv6local=0:0:0:0:0:0:0:1`, | ||
}, | ||
{ | ||
doc: "Bad address, colon sep", | ||
input: []string{`myhost:192.notanipaddress.1`}, | ||
expectedErr: `invalid IP address in add-host: "192.notanipaddress.1"`, | ||
}, | ||
{ | ||
doc: "Bad address, eq sep", | ||
input: []string{`myhost=192.notanipaddress.1`}, | ||
expectedErr: `invalid IP address in add-host: "192.notanipaddress.1"`, | ||
}, | ||
{ | ||
doc: "No sep", | ||
input: []string{`thathost-nosemicolon10.0.0.1`}, | ||
expectedErr: `bad format for add-host: "thathost-nosemicolon10.0.0.1"`, | ||
}, | ||
{ | ||
doc: "Bad IPv6", | ||
input: []string{`anipv6host:::::1`}, | ||
expectedErr: `invalid IP address in add-host: "::::1"`, | ||
}, | ||
{ | ||
doc: "Bad IPv6, trailing colons", | ||
input: []string{`ipv6local:::0::`}, | ||
expectedErr: `invalid IP address in add-host: "::0::"`, | ||
}, | ||
{ | ||
doc: "Bad IPv6, missing close bracket", | ||
input: []string{`ipv6addr=[::1`}, | ||
expectedErr: `invalid IP address in add-host: "[::1"`, | ||
}, | ||
{ | ||
doc: "Bad IPv6, missing open bracket", | ||
input: []string{`ipv6addr=::1]`}, | ||
expectedErr: `invalid IP address in add-host: "::1]"`, | ||
}, | ||
{ | ||
doc: "Missing address, colon sep", | ||
input: []string{`myhost.invalid:`}, | ||
expectedErr: `invalid IP address in add-host: ""`, | ||
}, | ||
{ | ||
doc: "Missing address, eq sep", | ||
input: []string{`myhost.invalid=`}, | ||
expectedErr: `invalid IP address in add-host: ""`, | ||
}, | ||
{ | ||
doc: "No input", | ||
input: []string{``}, | ||
expectedErr: `bad format for add-host: ""`, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
tc := tc | ||
if tc.expectedOut == "" { | ||
tc.expectedOut = strings.Join(tc.input, ",") | ||
} | ||
t.Run(tc.doc, func(t *testing.T) { | ||
actualOut, actualErr := toBuildkitExtraHosts(context.TODO(), tc.input, nil) | ||
if tc.expectedErr == "" { | ||
require.Equal(t, tc.expectedOut, actualOut) | ||
require.Nil(t, actualErr) | ||
} else { | ||
require.Zero(t, actualOut) | ||
require.Error(t, actualErr, tc.expectedErr) | ||
} | ||
}) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we update the reference docs in
buildx/commands/build.go
Line 489 in cb37886
Guess it should be
... (format: "host=ip")
if this format is the preferred one now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes - will do! Thank you.