Skip to content

Commit

Permalink
Fix the latest launch problem in 2256, fixes #2256 (#2304)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay committed Jun 11, 2020
1 parent c60d21d commit f72957d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 11 deletions.
48 changes: 48 additions & 0 deletions cmd/ddev/cmd/commands_test.go
@@ -1,13 +1,17 @@
package cmd

import (
"github.com/drud/ddev/pkg/ddevapp"
"github.com/drud/ddev/pkg/exec"
"github.com/drud/ddev/pkg/fileutil"
"github.com/drud/ddev/pkg/nodeps"
"github.com/drud/ddev/pkg/testcommon"
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 +82,47 @@ 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)

// Create a temporary directory and switch to it.
tmpdir := testcommon.CreateTmpDir(t.Name())
defer testcommon.CleanupDir(tmpdir)
defer testcommon.Chdir(tmpdir)()

_ = os.Setenv("DDEV_DEBUG", "true")
app, err := ddevapp.NewApp(tmpdir, false, "")
require.NoError(t, err)
err = app.WriteConfig()
require.NoError(t, err)
err = app.Start()
require.NoError(t, err)
defer func() {
_ = app.Stop(true, false)
}()

// This only tests the https port changes, but that might be enough
for _, routerPort := range []string{nodeps.DdevDefaultRouterHTTPSPort, "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
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 f72957d

Please sign in to comment.