Skip to content

Commit

Permalink
feat: adds support to ephemeral ports for 80/443, fixes ddev#5326 (dd…
Browse files Browse the repository at this point in the history
…ev#6414)

Co-authored-by: Stanislav Zhuk <[email protected]>
  • Loading branch information
agviu and stasadev authored Aug 23, 2024
1 parent 8b705b8 commit 83dc3c9
Show file tree
Hide file tree
Showing 25 changed files with 610 additions and 257 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ jobs:
- name: Override environment variables for push-pull-test-platforms
run: |
echo "MAKE_TARGET=test" >> $GITHUB_ENV
echo "TESTARGS=-failfast -run '(TestDdevFullSite.*|TestDdevImportFiles|TestDdevAllDatabases|TestComposerCreateCmd|Test.*(Push|Pull))'" >> $GITHUB_ENV
echo "TESTARGS=-failfast -run '(TestDdevFullSite.*|TestDdevImportFiles|TestDdevAllDatabases|TestComposerCreateCmd|Test.*(Push|Pull)|TestAutocomplet)'" >> $GITHUB_ENV
echo "GOTEST_SHORT=" >> $GITHUB_ENV
echo "DDEV_PLATFORM_API_TOKEN=${{ secrets.DDEV_PLATFORM_API_TOKEN }}" >> $GITHUB_ENV
echo "DDEV_UPSUN_API_TOKEN=${{ secrets.DDEV_UPSUN_API_TOKEN }}" >> $GITHUB_ENV
Expand Down
4 changes: 2 additions & 2 deletions cmd/ddev/cmd/auth-ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (

// TestCmdAuthSSH runs `ddev auth ssh` and checks that it actually worked out.
func TestCmdAuthSSH(t *testing.T) {
if nodeps.IsAppleSilicon() {
t.Skip("Skipping TestCmdAuthSSH on Mac M1 because of useless Docker Desktop failures to connect")
if nodeps.IsAppleSilicon() && dockerutil.IsDockerDesktop() {
t.Skip("Skipping TestCmdAuthSSH on Apple Silicon because of Docker Desktop failures to connect")
}

assert := asrt.New(t)
Expand Down
18 changes: 13 additions & 5 deletions cmd/ddev/cmd/autocompletion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ddev/ddev/pkg/fileutil"
"github.com/ddev/ddev/pkg/globalconfig"
"github.com/ddev/ddev/pkg/testcommon"
"github.com/ddev/ddev/pkg/util"
asrt "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -25,9 +26,11 @@ func TestAutocompletionForStopCmd(t *testing.T) {
if len(TestSites) < 2 {
t.Skip("Must have at least two test sites to test autocompletion")
}
origDir, _ := os.Getwd()

t.Cleanup(func() {
removeSites()
_ = os.Chdir(origDir)
})

// Make sure we have some sites.
Expand Down Expand Up @@ -100,8 +103,11 @@ func TestAutocompletionForStartCmd(t *testing.T) {
t.Skip("Must have at least two test sites to test autocompletion")
}

origDir, _ := os.Getwd()

t.Cleanup(func() {
removeSites()
_ = os.Chdir(origDir)
})

// Make sure we have some sites.
Expand Down Expand Up @@ -164,17 +170,21 @@ func TestAutocompletionForStartCmd(t *testing.T) {
assert.Empty(filteredOut)
}

// TestAutocompletionForStartCmd checks autocompletion of project names for ddev describe
// TestAutocompletionForDescribeCmd checks autocompletion of project names for ddev describe
func TestAutocompletionForDescribeCmd(t *testing.T) {
assert := asrt.New(t)

// Skip if we don't have enough tests.
if len(TestSites) < 2 {
t.Skip("Must have at least two test sites to test autocompletion")
}
origDir, _ := os.Getwd()

t.Cleanup(func() {
removeSites()
pwd, err := os.Getwd()
util.Debug("pwd=%s, err=%v", pwd, err)
_ = os.Chdir(origDir)
})

// Make sure we have some sites.
Expand Down Expand Up @@ -235,12 +245,11 @@ func TestAutocompletionForCustomCmds(t *testing.T) {
testdataCustomCommandsDir := filepath.Join(origDir, "testdata", t.Name())

t.Cleanup(func() {
err = os.Chdir(origDir)
assert.NoError(err)
err = app.Stop(true, false)
assert.NoError(err)
testcommon.ResetGlobalDdevDir(t, tmpXdgConfigHomeDir)
_ = fileutil.PurgeDirectory(filepath.Join(site.Dir, ".ddev", "commands"))
_ = os.Chdir(origDir)
})
err = app.Start()
require.NoError(t, err)
Expand Down Expand Up @@ -301,12 +310,11 @@ func TestAutocompleteTermsForCustomCmds(t *testing.T) {
testdataCustomCommandsDir := filepath.Join(origDir, "testdata", t.Name())

t.Cleanup(func() {
err = os.Chdir(origDir)
assert.NoError(err)
err = app.Stop(true, false)
assert.NoError(err)
testcommon.ResetGlobalDdevDir(t, tmpXdgConfigHomeDir)
_ = fileutil.PurgeDirectory(filepath.Join(site.Dir, ".ddev", "commands"))
_ = os.Chdir(origDir)
})
err = app.Start()
require.NoError(t, err)
Expand Down
5 changes: 4 additions & 1 deletion cmd/ddev/cmd/composer-create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ func TestComposerCreateCmd(t *testing.T) {

func TestComposerCreateAutocomplete(t *testing.T) {
assert := asrt.New(t)

// DDEV_DEBUG may result in extra output that we don't want
origDdevDebug := os.Getenv("DDEV_DEBUG")
_ = os.Unsetenv("DDEV_DEBUG")
// Change to the directory for the project to test.
// We don't really care what the project is, they should
// all have composer installed in the web container.
Expand All @@ -242,6 +244,7 @@ func TestComposerCreateAutocomplete(t *testing.T) {
t.Cleanup(func() {
err = os.Chdir(origDir)
assert.NoError(err)
_ = os.Setenv("DDEV_DEBUG", origDdevDebug)
})

// Make sure the sites exist and are running
Expand Down
27 changes: 12 additions & 15 deletions cmd/ddev/cmd/composer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ddev/ddev/pkg/nodeps"
"github.com/ddev/ddev/pkg/testcommon"
asrt "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestComposerCmdCreateConfigInstall(t *testing.T) {
Expand Down Expand Up @@ -165,33 +166,29 @@ func TestComposerCmdCreateRequireRemove(t *testing.T) {
}

func TestComposerAutocomplete(t *testing.T) {
assert := asrt.New(t)

// Change to the directory for the project to test.
// We don't really care what the project is, they should
// all have composer installed in the web container.
origDir, err := os.Getwd()
assert.NoError(err)
err = os.Chdir(TestSites[0].Dir)
assert.NoError(err)
origDir, _ := os.Getwd()
origDdevDebug := os.Getenv("DDEV_DEBUG")
_ = os.Unsetenv("DDEV_DEBUG")
err := os.Chdir(TestSites[0].Dir)
require.NoError(t, err)

t.Cleanup(func() {
err = os.Chdir(origDir)
assert.NoError(err)
_ = os.Chdir(origDir)
_ = os.Setenv("DDEV_DEBUG", origDdevDebug)
})

// Make sure the sites exist and are running
err = addSites()
assert.NoError(err)
require.NoError(t, err)

// Pressing tab after `composer completion` should result in the completion "bash"
out, err := exec.RunHostCommand(DdevBin, "__complete", "composer", "completion", "")
assert.NoError(err)
require.NoError(t, err)
// Completions are terminated with ":4", so just grab the stuff before that
completions, _, found := strings.Cut(out, ":")
assert.True(found)
assert.Equal(strings.TrimSpace(completions), "bash")

err = os.Chdir(origDir)
assert.NoError(err)
require.True(t, found)
require.Equal(t, "bash", strings.TrimSpace(completions))
}
14 changes: 6 additions & 8 deletions cmd/ddev/cmd/debug-nfsmount_test.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package cmd

import (
"os"
"path/filepath"
"runtime"
"testing"

"github.com/ddev/ddev/pkg/dockerutil"
"github.com/ddev/ddev/pkg/exec"
"github.com/ddev/ddev/pkg/fileutil"
"github.com/ddev/ddev/pkg/nodeps"
"github.com/ddev/ddev/pkg/testcommon"
asrt "github.com/stretchr/testify/assert"
"os"
"path/filepath"
"runtime"
"testing"
)

// TestDebugNFSMount tries out the `ddev debug nfsmount` command.
// It requires nfsd running of course.
func TestDebugNFSMount(t *testing.T) {
if nodeps.IsWSL2() || dockerutil.IsColima() || dockerutil.IsLima() || dockerutil.IsOrbstack() {
t.Skip("Skipping on WSL2/Lima/Colima since NFS is not used there")
}
t.Skip("Skipping because NFS is deprecated")
assert := asrt.New(t)

oldDir, err := os.Getwd()
Expand Down
8 changes: 3 additions & 5 deletions cmd/ddev/cmd/debug-router-nginx-config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ package cmd

import (
"fmt"
"testing"

"github.com/ddev/ddev/pkg/ddevapp"
"github.com/ddev/ddev/pkg/exec"
"github.com/ddev/ddev/pkg/globalconfig"
asrt "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)

// TestDebugRouterNginxConfigCmd ensures the debug router-nginx-config prints the nginx config to stdout
func TestDebugRouterNginxConfigCmd(t *testing.T) {
if globalconfig.DdevGlobalConfig.IsTraefikRouter() {
t.Skip("Skipping when UseTrafik is set, as it's invalid")
}
t.Skip("Skipping because the nginx-proxy router is deprecated")
assert := asrt.New(t)

site := TestSites[0]
Expand Down
70 changes: 37 additions & 33 deletions cmd/ddev/cmd/describe_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package cmd

import (
"encoding/json"
"fmt"
"github.com/ddev/ddev/pkg/globalconfig"
"github.com/stretchr/testify/require"
"os"
"strings"
"testing"

"encoding/json"

"os"
"github.com/ddev/ddev/pkg/globalconfig"
"github.com/stretchr/testify/require"

"github.com/ddev/ddev/pkg/ddevapp"
"github.com/ddev/ddev/pkg/exec"
Expand Down Expand Up @@ -50,8 +49,17 @@ func TestDescribeBadArgs(t *testing.T) {

// TestCmdDescribe tests that the describe command works properly when using the binary.
func TestCmdDescribe(t *testing.T) {
assert := asrt.New(t)

origDdevDebug := os.Getenv("DDEV_DEBUG")
_ = os.Unsetenv("DDEV_DEBUG")
origDir, _ := os.Getwd()
tmpDir := testcommon.CreateTmpDir("")

t.Cleanup(func() {
_ = os.Setenv("DDEV_DEBUG", origDdevDebug)
_ = os.Chdir(origDir)
_ = os.RemoveAll(tmpDir)
})
out, err := exec.RunHostCommand(DdevBin, "config", "global", "--simple-formatting=false", "--table-style=default")
require.NoError(t, err, "ddev config global failed with output: '%s'", out)
t.Logf("ddev config global output: '%s'", out)
Expand All @@ -65,34 +73,30 @@ func TestCmdDescribe(t *testing.T) {
require.NoError(t, err)

// First, try to do a describe from another directory.
tmpdir := testcommon.CreateTmpDir("")
cleanup := testcommon.Chdir(tmpdir)
defer testcommon.CleanupDir(tmpdir)

out, err := exec.RunHostCommand(DdevBin, "describe", v.Name)
assert.NoError(err)
assert.Contains(string(out), "SERVICE")
assert.Contains(string(out), "STAT")
assert.Contains(string(out), v.Name)
assert.Contains(string(out), "OK")

cleanup()
err = os.Chdir(tmpDir)
require.NoError(t, err)

cleanup = v.Chdir()
defer cleanup()
out, err = exec.RunHostCommand(DdevBin, "describe", v.Name)
require.NoError(t, err, "output=%s", out)
require.Contains(t, string(out), "SERVICE")
require.Contains(t, string(out), "STAT")
require.Contains(t, string(out), v.Name)
require.Contains(t, string(out), "OK")

err = os.Chdir(v.Dir)
require.NoError(t, err)
out, err = exec.RunHostCommand(DdevBin, "describe")
assert.NoError(err)
assert.Contains(string(out), "SERVICE")
assert.Contains(string(out), "STAT")
assert.Contains(string(out), v.Name)
assert.Contains(string(out), "OK")
require.NoError(t, err, "output=%s", out)
require.Contains(t, string(out), "SERVICE")
require.Contains(t, string(out), "STAT")
require.Contains(t, string(out), v.Name)
require.Contains(t, string(out), "OK")

// Test describe in current directory with json flag
out, err = exec.RunHostCommand(DdevBin, "describe", "-j")
assert.NoError(err)
require.NoError(t, err, "output=%s", out)
logItems, err := unmarshalJSONLogs(out)
require.NoError(t, err, "Unable to unmarshal ===\n%s\n===\n", logItems)
require.NoError(t, err, "Unable to unmarshal ===\n%s\n===\n", out)

// The description log should be next last item; there may be a warning
// or other info before that.
Expand All @@ -107,13 +111,13 @@ func TestCmdDescribe(t *testing.T) {
}
}
require.True(t, rawFound, "did not find 'raw' in item in logItems\n===\n%s\n===\n", out)
assert.EqualValues("running", raw["status"])
assert.EqualValues("running", raw["status_desc"])
assert.EqualValues(v.Name, raw["name"])
assert.Equal(ddevapp.RenderHomeRootedDir(v.Dir), raw["shortroot"].(string))
assert.EqualValues(v.Dir, raw["approot"].(string))
require.EqualValues(t, "running", raw["status"])
require.EqualValues(t, "running", raw["status_desc"])
require.EqualValues(t, v.Name, raw["name"])
require.Equal(t, ddevapp.RenderHomeRootedDir(v.Dir), raw["shortroot"].(string))
require.EqualValues(t, v.Dir, raw["approot"].(string))

assert.NotEmpty(item["msg"])
require.NotEmpty(t, item["msg"])
}
}

Expand Down
12 changes: 8 additions & 4 deletions cmd/ddev/cmd/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package cmd

import (
"fmt"
"github.com/ddev/ddev/pkg/ddevapp"
"github.com/ddev/ddev/pkg/fileutil"
"github.com/ddev/ddev/pkg/util"
"github.com/stretchr/testify/require"
"os"
"path/filepath"
"strings"
"testing"

"github.com/ddev/ddev/pkg/ddevapp"
"github.com/ddev/ddev/pkg/fileutil"
"github.com/ddev/ddev/pkg/util"
"github.com/stretchr/testify/require"

"github.com/ddev/ddev/pkg/exec"
asrt "github.com/stretchr/testify/assert"
)
Expand All @@ -32,6 +33,8 @@ func TestCmdExec(t *testing.T) {
assert := asrt.New(t)
origDir, err := os.Getwd()
require.NoError(t, err)
origDdevDebug := os.Getenv("DDEV_DEBUG")
_ = os.Unsetenv("DDEV_DEBUG")

site := TestSites[0]
err = os.Chdir(site.Dir)
Expand All @@ -40,6 +43,7 @@ func TestCmdExec(t *testing.T) {
t.Cleanup(func() {
err = os.Chdir(origDir)
assert.NoError(err)
_ = os.Setenv("DDEV_DEBUG", origDdevDebug)
})
app, err := ddevapp.GetActiveApp(site.Name)
assert.NoError(err)
Expand Down
3 changes: 3 additions & 0 deletions cmd/ddev/cmd/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ func TestCmdGetInstalled(t *testing.T) {
if os.Getenv("DDEV_RUN_GET_TESTS") != "true" {
t.Skip("Skipping because DDEV_RUN_GET_TESTS is not set")
}
origDdevDebug := os.Getenv("DDEV_DEBUG")
_ = os.Unsetenv("DDEV_DEBUG")
assert := asrt.New(t)

origDir, _ := os.Getwd()
Expand All @@ -175,6 +177,7 @@ func TestCmdGetInstalled(t *testing.T) {
err = os.Chdir(origDir)
assert.NoError(err)
_ = os.RemoveAll(filepath.Join(globalconfig.GetGlobalDdevDir(), "commands/web/global-touched"))
_ = os.Setenv("DDEV_DEBUG", origDdevDebug)
})

out, err := exec.RunHostCommand(DdevBin, "get", "ddev/ddev-memcached", "--json-output")
Expand Down
Loading

0 comments on commit 83dc3c9

Please sign in to comment.