mirror of
https://github.com/docker/compose.git
synced 2025-07-27 07:34:10 +02:00
Merge pull request #356 from docker/fix-non-interactive
Add check on exec looking for arguments
This commit is contained in:
commit
16acc36033
@ -193,6 +193,10 @@ func getGroupAndContainerName(containerID string) (groupName string, containerNa
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cs *aciContainerService) Exec(ctx context.Context, name string, command string, reader io.Reader, writer io.Writer) error {
|
func (cs *aciContainerService) Exec(ctx context.Context, name string, command string, reader io.Reader, writer io.Writer) error {
|
||||||
|
err := verifyExecCommand(command)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
groupName, containerAciName := getGroupAndContainerName(name)
|
groupName, containerAciName := getGroupAndContainerName(name)
|
||||||
containerExecResponse, err := execACIContainer(ctx, cs.ctx, command, groupName, containerAciName)
|
containerExecResponse, err := execACIContainer(ctx, cs.ctx, command, groupName, containerAciName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -208,6 +212,15 @@ func (cs *aciContainerService) Exec(ctx context.Context, name string, command st
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func verifyExecCommand(command string) error {
|
||||||
|
tokens := strings.Split(command, " ")
|
||||||
|
if len(tokens) > 1 {
|
||||||
|
return errors.New("ACI exec command does not accept arguments to the command. " +
|
||||||
|
"Only the binary should be specified")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (cs *aciContainerService) Logs(ctx context.Context, containerName string, req containers.LogsRequest) error {
|
func (cs *aciContainerService) Logs(ctx context.Context, containerName string, req containers.LogsRequest) error {
|
||||||
groupName, containerAciName := getGroupAndContainerName(containerName)
|
groupName, containerAciName := getGroupAndContainerName(containerName)
|
||||||
var tail *int32
|
var tail *int32
|
||||||
|
@ -61,6 +61,15 @@ func (suite *BackendSuiteTest) TestErrorMessageRunSingleContainerNameWithCompose
|
|||||||
Expect(err.Error()).To(Equal("invalid container name. ACI container name cannot include \"_\""))
|
Expect(err.Error()).To(Equal("invalid container name. ACI container name cannot include \"_\""))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *BackendSuiteTest) TestVerifyCommand() {
|
||||||
|
err := verifyExecCommand("command") // Command without an argument
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
err = verifyExecCommand("command argument") // Command with argument
|
||||||
|
Expect(err).NotTo(BeNil())
|
||||||
|
Expect(err.Error()).To(Equal("ACI exec command does not accept arguments to the command. " +
|
||||||
|
"Only the binary should be specified"))
|
||||||
|
}
|
||||||
|
|
||||||
func TestBackendSuite(t *testing.T) {
|
func TestBackendSuite(t *testing.T) {
|
||||||
RegisterTestingT(t)
|
RegisterTestingT(t)
|
||||||
suite.Run(t, new(BackendSuiteTest))
|
suite.Run(t, new(BackendSuiteTest))
|
||||||
|
@ -150,6 +150,15 @@ func (s *E2eACISuite) TestACIBackend() {
|
|||||||
Expect(output).To(ContainSubstring("GET"))
|
Expect(output).To(ContainSubstring("GET"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
s.T().Run("exec command", func(t *testing.T) {
|
||||||
|
output := s.NewDockerCommand("exec", testContainerName, "pwd").ExecOrDie()
|
||||||
|
Expect(output).To(ContainSubstring("/"))
|
||||||
|
|
||||||
|
output = s.NewDockerCommand("exec", testContainerName, "echo", "fail_with_argument").ExecOrDie()
|
||||||
|
Expect(output).To(ContainSubstring("ACI exec command does not accept arguments to the command. " +
|
||||||
|
"Only the binary should be specified"))
|
||||||
|
})
|
||||||
|
|
||||||
s.T().Run("follow logs from nginx", func(t *testing.T) {
|
s.T().Run("follow logs from nginx", func(t *testing.T) {
|
||||||
timeChan := make(chan time.Time)
|
timeChan := make(chan time.Time)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user