-
Notifications
You must be signed in to change notification settings - Fork 798
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support the containers.conf container_name_as_hostname option
When containers.conf has the "container_name_as_hostname" option set, use that value, with values that don't fit `[A-Za-z0-9][A-Za-z0-9.-]+` stripped out. Signed-off-by: Nalin Dahyabhai <[email protected]>
- Loading branch information
Showing
5 changed files
with
94 additions
and
2 deletions.
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,31 @@ | ||
package buildah | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMapContainerNameToHostname(t *testing.T) { | ||
cases := [][2]string{ | ||
{"trivial", "trivial"}, | ||
{"Nottrivial", "Nottrivial"}, | ||
{"0Nottrivial", "0Nottrivial"}, | ||
{"0Nottrivi-al", "0Nottrivi-al"}, | ||
{"-0Nottrivi-al", "0Nottrivi-al"}, | ||
{".-0Nottrivi-.al", "0Nottrivi-.al"}, | ||
{".-0Nottrivi-.al0123456789", "0Nottrivi-.al0123456789"}, | ||
{".-0Nottrivi-.al0123456789+0123456789", "0Nottrivi-.al01234567890123456789"}, | ||
{".-0Nottrivi-.al0123456789+0123456789/0123456789", "0Nottrivi-.al012345678901234567890123456789"}, | ||
{".-0Nottrivi-.al0123456789+0123456789/0123456789%0123456789", "0Nottrivi-.al0123456789012345678901234567890123456789"}, | ||
{".-0Nottrivi-.al0123456789+0123456789/0123456789%0123456789_0123456789", "0Nottrivi-.al01234567890123456789012345678901234567890123456789"}, | ||
{".-0Nottrivi-.al0123456789+0123456789/0123456789%0123456789_0123456789:0123456", "0Nottrivi-.al012345678901234567890123456789012345678901234567890"}, | ||
{".-0Nottrivi-.al0123456789+0123456789/0123456789%0123456789_0123456789:0123456789", "0Nottrivi-.al012345678901234567890123456789012345678901234567890"}, | ||
} | ||
for i := range cases { | ||
t.Run(cases[i][0], func(t *testing.T) { | ||
sanitized := mapContainerNameToHostname(cases[i][0]) | ||
assert.Equalf(t, cases[i][1], sanitized, "mapping container name %q to a valid hostname", cases[i][0]) | ||
}) | ||
} | ||
} |
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
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