MCPcopy Create free account
hub / github.com/ddev/ddev / TestGetWebContainerDirectURLsWithDockerIPError

Function TestGetWebContainerDirectURLsWithDockerIPError

pkg/ddevapp/ddevapp_test.go:3910–3964  ·  view source on GitHub ↗

TestGetWebContainerDirectURLsWithDockerIPError tests behavior when GetDockerIP returns an error

(t *testing.T)

Source from the content-addressed store, hash-verified

3908
3909// TestGetWebContainerDirectURLsWithDockerIPError tests behavior when GetDockerIP returns an error
3910func TestGetWebContainerDirectURLsWithDockerIPError(t *testing.T) {
3911 assert := asrt.New(t)
3912 app := &ddevapp.DdevApp{}
3913
3914 // Make sure this leaves us in the original test directory
3915 testDir, _ := os.Getwd()
3916 //nolint: errcheck
3917 defer os.Chdir(testDir)
3918
3919 site := TestSites[0]
3920 switchDir := site.Chdir()
3921 defer switchDir()
3922
3923 err := app.Init(site.Dir)
3924 assert.NoError(err)
3925
3926 // Start the app to ensure we have a running container
3927 err = app.Start()
3928 assert.NoError(err)
3929
3930 t.Cleanup(func() {
3931 err = app.Stop(true, false)
3932 assert.NoError(err)
3933 })
3934
3935 // Save original DockerHost to restore it later
3936 _, origDockerHost, err := dockerutil.GetDockerContextNameAndHost()
3937 require.NoError(t, err)
3938 t.Cleanup(func() {
3939 err = dockerutil.ResetDockerHost(origDockerHost)
3940 require.NoError(t, err)
3941 })
3942
3943 // Set an invalid DockerHost to force GetDockerIP to return an error
3944 err = dockerutil.ResetDockerHost("unix:///nonexistent/docker.sock")
3945 require.NoError(t, err)
3946
3947 // Even with an invalid DockerHost, the functions should still work
3948 // because they handle the error internally by using the default IP (127.0.0.1)
3949 httpURL := app.GetWebContainerDirectHTTPURL()
3950 httpsURL := app.GetWebContainerDirectHTTPSURL()
3951
3952 // The URLs should still be generated with the default Docker IP (127.0.0.1)
3953 // A warning will be logged but the functions should still return valid URLs
3954 _, err = app.GetPublishedPortForPrivatePort("web", 80)
3955 assert.NoError(err, "GetPublishedPortForPrivatePort should not return an error for HTTP port")
3956
3957 // Verify that the URLs contain the default Docker IP (127.0.0.1)
3958 assert.Contains(httpURL, "http://127.0.0.1:", "GetWebContainerDirectHTTPURL should return a URL with the default Docker IP (127.0.0.1)")
3959 assert.Contains(httpsURL, "https://127.0.0.1:", "GetWebContainerDirectHTTPSURL should return a URL with the default Docker IP (127.0.0.1)")
3960
3961 // Verify that the URLs contain valid ports
3962 assert.NotContains(httpURL, ":0", "HTTP URL should not contain port 0")
3963 assert.NotContains(httpsURL, ":0", "HTTPS URL should not contain port 0")
3964}
3965
3966// TestPHPWebserverType checks usage of
3967// - webserver_type

Callers

nothing calls this directly

Calls 10

InitMethod · 0.95
StartMethod · 0.95
StopMethod · 0.95
ResetDockerHostFunction · 0.92
ChdirMethod · 0.80
CleanupMethod · 0.80

Tested by

no test coverage detected