From 318233978d4c33d68f85decd1b4ea00ed3907ed0 Mon Sep 17 00:00:00 2001 From: Sharif Elgamal Date: Thu, 10 Jun 2021 14:34:24 -0700 Subject: [PATCH] make sure to only run one proxy test or the other --- site/content/en/docs/contrib/tests.en.md | 6 +++++ test/integration/functional_test.go | 31 ++++++++++++++++++++---- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/site/content/en/docs/contrib/tests.en.md b/site/content/en/docs/contrib/tests.en.md index 47ea10dca5..94620c005b 100644 --- a/site/content/en/docs/contrib/tests.en.md +++ b/site/content/en/docs/contrib/tests.en.md @@ -94,6 +94,9 @@ check functionality of minikube after evaluating docker-env check functionality of minikube after evaluating podman-env #### validateStartWithProxy +either calls validateStartWithRegularProxy or validateStartWithCorpProxy depending on the test environment + +#### validateStartWithRegularProxy makes sure minikube start respects the HTTP_PROXY environment variable #### validateAuditAfterStart @@ -172,6 +175,9 @@ asserts that for a given runtime, the other runtimes disabled, for example for c #### validateUpdateContextCmd asserts basic "update-context" command functionality +#### validateStartWithCorpProxy +ensures that minikube can run behind a custom proxy + #### validateMountCmd verifies the minikube mount command works properly diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index abfcc516e9..6133522102 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -93,7 +93,6 @@ func TestFunctional(t *testing.T) { {"MinikubeKubectlCmdDirectly", validateMinikubeKubectlDirectCall}, {"ExtraConfig", validateExtraConfig}, // Ensure extra cmdline config change is saved {"ComponentHealth", validateComponentHealth}, - {"StartWithCorpProxy", validateStartWithCorpProxy}, } for _, tc := range tests { tc := tc @@ -518,8 +517,17 @@ func validatePodmanEnv(ctx context.Context, t *testing.T, profile string) { } } -// validateStartWithProxy makes sure minikube start respects the HTTP_PROXY environment variable +// validateStartWithProxy either calls validateStartWithRegularProxy or validateStartWithCorpProxy depending on the test environment func validateStartWithProxy(ctx context.Context, t *testing.T, profile string) { + if GithubActionRunner() { + validateStartWithCorpProxy(ctx, t, profile) + } else { + validateStartWithRegularProxy(ctx, t, profile) + } +} + +// validateStartWithRegularProxy makes sure minikube start respects the HTTP_PROXY environment variable +func validateStartWithRegularProxy(ctx context.Context, t *testing.T, profile string) { defer PostMortemLogs(t, profile) srv, err := startHTTPProxy(t) @@ -1783,11 +1791,16 @@ users: } } +// validateStartWithCorpProxy ensures that minikube can run behind a custom proxy func validateStartWithCorpProxy(ctx context.Context, t *testing.T, profile string) { if !GithubActionRunner() { t.Skip("Only run mitmproxy test on github actions") } + if runtime.GOOS != "linux" { + t.Skip("Only run mitmproxy test on linux") + } + defer PostMortemLogs(t, profile) // Pull down the mitmproxy docker image @@ -1805,7 +1818,10 @@ func validateStartWithCorpProxy(ctx context.Context, t *testing.T, profile strin // Start an interactive session (since mitmproxy requires it) asyncronously // This will create the necessary .mitmproxy directory with its certs mitmCmd := exec.CommandContext(ctx, "docker", "run", "-it", "--rm", "--name", "mitmproxy", "-v", certDir, ":/home/mitmproxy/.mitmproxy", "-p", "8080:8080", "mitmproxy/mitmproxy") - go Run(t, mitmCmd) + _, err = Start(t, mitmCmd) + if err != nil { + t.Fatalf("starting mitmproxy failed: %v", err) + } // Make sure the container is running and grab the containerid for future use containerID := "" @@ -1814,9 +1830,14 @@ func validateStartWithCorpProxy(ctx context.Context, t *testing.T, profile strin if err != nil { t.Fatalf("docker failure: %v", err) } - containerID = string(rr.Stdout.Bytes()) + containerID = rr.Stdout.String() } - defer Run(t, exec.CommandContext(ctx, "docker", "stop", containerID)) + defer func() { + _, err := Run(t, exec.CommandContext(ctx, "docker", "stop", containerID)) + if err != nil { + t.Logf("failed to stop docker: %v", err) + } + }() // Add a symlink from the cert to the correct directory certFile := path.Join(certDir, "mitmproxy-ca-cert.pem")