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

Add test case to document env header contains whitespace error as expected behavior. #5156

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/reference/commandline/container_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ This starts an `ubuntu` container with access to the specified CDI device,
- A valid CDI specification (JSON or YAML file) for the requested device is
available on the system running the daemon, in one of the configured CDI
specification directories.
- The CDI feature has been enabled in the daemon; see [Enable CDI
- The CDI feature has been enabled in the daemon. See [Enable CDI
devices](https://docs.docker.com/reference/cli/dockerd/#enable-cdi-devices).

### <a name="attach"></a> Attach to STDIN/STDOUT/STDERR (-a, --attach)
Expand Down Expand Up @@ -1587,4 +1587,4 @@ The `docker run` command is equivalent to the following API calls:
- If that call returns a 404 (image not found), and depending on the `--pull` option ("always", "missing", "never") the call can trigger a `docker pull <image>`.
- `/containers/create` again after pulling the image.
- `/containers/(id)/start` to start the container.
- `/containers/(id)/attach` to attach to the container when starting with the `-it` flags for interactive containers.
- `/containers/(id)/attach` to attach to the container when starting with the `-it` flags for interactive containers.
19 changes: 19 additions & 0 deletions opts/envfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,25 @@ func TestParseEnvFileNonExistentFile(t *testing.T) {
}
}

// Test TestParseEnvFile for a badly formatted header
func TestParseEnvFileFormattedWithSpace(t *testing.T) {
content := `
[config 1]
foo=bar
f=quux
`
tmpFile := tmpFileWithContent(t, content)

_, err := ParseEnvFile(tmpFile)
if _, ok := err.(ErrBadKey); !ok {
t.Fatalf("Expected an ErrBadKey, got [%v]", err)
}
expectedMessage := "poorly formatted environment: variable '[config 1]' contains whitespaces"
if err.Error() != expectedMessage {
t.Fatalf("Expected [%v], got [%v]", expectedMessage, err.Error())
}
}

// Test ParseEnvFile for a badly formatted file
func TestParseEnvFileBadlyFormattedFile(t *testing.T) {
content := `foo=bar
Expand Down
Loading