Skip to content

Commit

Permalink
Fix the latest launch problem in 2256, fixes ddev#2256
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay committed Jun 9, 2020
1 parent 1d64b85 commit 2b2979f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 11 deletions.
44 changes: 44 additions & 0 deletions cmd/ddev/cmd/commands_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package cmd

import (
"github.com/drud/ddev/pkg/ddevapp"
"github.com/drud/ddev/pkg/exec"
"github.com/drud/ddev/pkg/fileutil"
asrt "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"os"
osexec "os/exec"
"path/filepath"
"strings"
"testing"
)

Expand Down Expand Up @@ -78,3 +80,45 @@ columns_priv`)
assert.NoError(err, "Failed to run ddev help %s", c)
}
}

// TestLaunchCommand tests that the launch command behaves all the ways it should behave
func TestLaunchCommand(t *testing.T) {
assert := asrt.New(t)
site := TestSites[0]
switchDir := site.Chdir()

_ = os.Setenv("DDEV_DEBUG", "true")
app, err := ddevapp.NewApp(site.Dir, false, "")
assert.NoError(err)
err = app.Start()
assert.NoError(err)
defer func() {
_ = app.Stop(true, false)
app.RouterHTTPSPort = ""
_ = app.WriteConfig()
switchDir()
}()

// This only tests the https port changes, but that might be enough
for _, routerPort := range []string{"443", "8443"} {
app.RouterHTTPSPort = routerPort
_ = app.WriteConfig()
err = app.Start()
assert.NoError(err)

desc, _ := app.Describe()
cases := map[string]string{
"": app.GetPrimaryURL(),
"-p": desc["phpmyadmin_https_url"].(string),
"-m": desc["mailhog_https_url"].(string),
}
for partialCommand, expect := range cases {
// Try with the base URL, simplest case
c := DdevBin + ` launch ` + partialCommand + ` | awk '/FULLURL/ {print $2}'`
out, err := exec.RunCommand("bash", []string{"-c", c})
out = strings.Trim(out, "\n")
assert.NoError(err, `couldn't run "%s"", output=%s`, c, out)
assert.Equal(expect, out, "ouptput of %s is incorrect with app.RouterHTTPSPort=%s: %s", c, app.RouterHTTPSPort, out)
}
}
}
24 changes: 14 additions & 10 deletions cmd/ddev/cmd/dotddev_assets/commands/host/launch
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ HTTPS=""
if [ ${DDEV_PRIMARY_URL%://*} = "https" ]; then HTTPS=true; fi

while :; do
case $1 in
case ${1:-} in
-h|-\?|--help)
show_help
exit
;;
-p|--phpmyadmin)
if [ "${HTTPS}" = "" ]; then
FULLURL="${FULLURL}:${DDEV_PHPMYADMIN_PORT}"
FULLURL="${FULLURL%:[0-9]*}:${DDEV_PHPMYADMIN_PORT}"
else
FULLURL="${FULLURL}:${DDEV_PHPMYADMIN_HTTPS_PORT}"
FULLURL="${FULLURL%:[0-9]*}:${DDEV_PHPMYADMIN_HTTPS_PORT}"
fi
;;
-m|--mailhog)
if [ "${HTTPS}" = "" ]; then
FULLURL="${FULLURL}:${DDEV_MAILHOG_PORT}"
FULLURL="${FULLURL%:[0-9]*}:${DDEV_MAILHOG_PORT}"
else
FULLURL="${FULLURL}:${DDEV_MAILHOG_HTTPS_PORT}"
FULLURL="${FULLURL%:[0-9]*}:${DDEV_MAILHOG_HTTPS_PORT}"
fi
;;

Expand All @@ -40,16 +40,20 @@ while :; do
*) # Default case: No more options, so break out of the loop.
break
esac

shift
done

if [ -n "${1:-}" ] ; then
if [[ ${1::1} != "/" ]] ; then
FULLURL="${FULLURL}/";
if [ -n "${1:-}" ] ; then
if [[ ${1::1} != "/" ]] ; then
FULLURL="${FULLURL}/";
fi

FULLURL="${FULLURL}${1}";
FULLURL="${FULLURL}${1}";
fi

if [ ! -z ${DDEV_DEBUG:-} ]; then
printf "FULLURL $FULLURL\n" && exit 0
fi

case $OSTYPE in
Expand Down
2 changes: 1 addition & 1 deletion cmd/ddev/cmd/packrd/packed-packr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2b2979f

Please sign in to comment.