Merge pull request #850 from docker/fix_path_appending

Fix path appending
This commit is contained in:
Guillaume Tardif 2020-10-29 17:47:13 +01:00 committed by GitHub
commit 810461179b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 9 deletions

View File

@ -24,6 +24,7 @@ import (
"os/signal" "os/signal"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings"
"syscall" "syscall"
"time" "time"
@ -73,13 +74,21 @@ func init() {
if err != nil { if err != nil {
fatal(errors.Wrap(err, "unable to get absolute bin path")) fatal(errors.Wrap(err, "unable to get absolute bin path"))
} }
if err := os.Setenv("PATH", fmt.Sprintf("%s:%s", os.Getenv("PATH"), path)); err != nil {
if err := os.Setenv("PATH", appendPaths(os.Getenv("PATH"), path)); err != nil {
panic(err) panic(err)
} }
// Seed random // Seed random
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
} }
func appendPaths(envPath string, path string) string {
if envPath == "" {
return path
}
return strings.Join([]string{envPath, path}, string(os.PathListSeparator))
}
func isContextAgnosticCommand(cmd *cobra.Command) bool { func isContextAgnosticCommand(cmd *cobra.Command) bool {
if cmd == nil { if cmd == nil {
return false return false

View File

@ -69,3 +69,8 @@ func TestCheckOwnCommand(t *testing.T) {
assert.Assert(t, !isContextAgnosticCommand(cmd.LogsCommand())) assert.Assert(t, !isContextAgnosticCommand(cmd.LogsCommand()))
assert.Assert(t, !isContextAgnosticCommand(cmd.PsCommand())) assert.Assert(t, !isContextAgnosticCommand(cmd.PsCommand()))
} }
func TestAppendPaths(t *testing.T) {
assert.Equal(t, appendPaths("", "/bin/path"), "/bin/path")
assert.Equal(t, appendPaths("path1", "binaryPath"), "path1"+string(os.PathListSeparator)+"binaryPath")
}

View File

@ -434,14 +434,7 @@ func TestContainerRunAttached(t *testing.T) {
endpoint = fmt.Sprintf("http://%s:%d", fqdn, port.HostPort) endpoint = fmt.Sprintf("http://%s:%d", fqdn, port.HostPort)
assert.Assert(t, !strings.Contains(followLogsProcess.Stdout(), "/test")) assert.Assert(t, !strings.Contains(followLogsProcess.Stdout(), "/test"))
checkRequest := func(t poll.LogT) poll.Result { HTTPGetWithRetry(t, endpoint+"/test", http.StatusNotFound, 2*time.Second, 60*time.Second)
r, _ := http.Get(endpoint + "/test")
if r != nil && r.StatusCode == http.StatusNotFound {
return poll.Success()
}
return poll.Continue("waiting for container to serve request")
}
poll.WaitOn(t, checkRequest, poll.WithDelay(1*time.Second), poll.WithTimeout(60*time.Second))
checkLog := func(t poll.LogT) poll.Result { checkLog := func(t poll.LogT) poll.Result {
if strings.Contains(followLogsProcess.Stdout(), "/test") { if strings.Contains(followLogsProcess.Stdout(), "/test") {