Skip to content

Commit

Permalink
Make TestPoweroffOnNewVersion work on Windows, fixes #2979 (#3031)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay committed Jun 3, 2021
1 parent ecd521d commit 74ae7f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 12 additions & 3 deletions cmd/ddev/cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"github.com/drud/ddev/pkg/dockerutil"
"github.com/drud/ddev/pkg/globalconfig"
"github.com/drud/ddev/pkg/nodeps"
"github.com/drud/ddev/pkg/util"
"github.com/stretchr/testify/require"
"os"
"runtime"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -255,22 +257,29 @@ func TestPoweroffOnNewVersion(t *testing.T) {
})

newStartTime := time.Now().Unix()
// Flaky test failures, possible failure of sync in docker desktop for Windows?
if runtime.GOOS == "windows" {
time.Sleep(5 * time.Second)
}
// We have to do the echo technique to get past the prompt about doing a ddev poweroff
out, err := exec.RunCommand("bash", []string{"-c", fmt.Sprintf("echo y | %s start", DdevBin)})
// On Windows we have to make sure we have git-bash, not the Windows bash.exe
bashPath := util.FindWindowsBashPath()
out, err := exec.RunCommand(bashPath, []string{"-c", fmt.Sprintf("echo y | '%s' start", DdevBin)})
assert.NoError(err)
assert.Contains(out, "ddev-ssh-agent container has been removed")
assert.Contains(out, "ssh-agent container is running")

apps = ddevapp.GetActiveProjects()
activeCount = len(apps)
assert.Equal(activeCount, 1)

// Verify that the ddev-router and ddev-ssh-agent have just been newly created
routerC, err := dockerutil.FindContainerByName("ddev-router")
assert.NoError(err)
require.NoError(t, err)
require.NotEmpty(t, routerC)
routerCreateTime := (*routerC).Created
sshC, err := dockerutil.FindContainerByName("ddev-ssh-agent")
assert.NoError(err)
require.NoError(t, err)
require.NotEmpty(t, sshC)
sshCreateTime := (*sshC).Created

Expand Down
5 changes: 4 additions & 1 deletion pkg/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,13 @@ func GetFirstWord(s string) string {
}

// FindWindowsBashPath returns the PATH to bash on Windows
// preferring git-bash
// preferring git-bash (or just "bash" elsewhere)
// On Windows we'll need the path to bash to execute anything.
// Returns empty string if not found, path if found
func FindWindowsBashPath() string {
if runtime.GOOS != "windows" {
return "bash"
}
windowsBashPath, err := osexec.LookPath(`C:\Program Files\Git\bin\bash.exe`)
if err != nil {
// This one could come back with the WSL bash, in which case we may have some trouble.
Expand Down

0 comments on commit 74ae7f8

Please sign in to comment.