Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJaime Martinez <jmartinez@gitlab.com>2021-06-09 07:48:56 +0300
committerJaime Martinez <jmartinez@gitlab.com>2021-06-10 04:01:46 +0300
commit7f676903538f06b73d83ce03e6bc1ab0db89a934 (patch)
treedb1189279216c315f7d36f054abf0798205bb3c7 /test
parent296105df9f56d10eb7ab1f4b716b2d8d35fdea8d (diff)
Use t.Cleanup
Diffstat (limited to 'test')
-rw-r--r--test/acceptance/helpers_test.go8
-rw-r--r--test/acceptance/metrics_test.go3
-rw-r--r--test/acceptance/serving_test.go45
3 files changed, 21 insertions, 35 deletions
diff --git a/test/acceptance/helpers_test.go b/test/acceptance/helpers_test.go
index 3c7a9d32..ec712b6d 100644
--- a/test/acceptance/helpers_test.go
+++ b/test/acceptance/helpers_test.go
@@ -233,7 +233,7 @@ func RunPagesProcessWithOutput(t *testing.T, pagesBinary string, listeners []Lis
return runPagesProcess(t, true, pagesBinary, listeners, promPort, nil, extraArgs...)
}
-func RunPagesProcessWithStubGitLabServer(t *testing.T, opts ...processOption) (*LogCaptureBuffer, func()) {
+func RunPagesProcessWithStubGitLabServer(t *testing.T, opts ...processOption) *LogCaptureBuffer {
chdir := false
chdirCleanup := testhelpers.ChdirInPath(t, "../../shared/pages", &chdir)
@@ -257,11 +257,13 @@ func RunPagesProcessWithStubGitLabServer(t *testing.T, opts ...processOption) (*
logBuf, cleanup := runPagesProcess(t, processCfg.wait, processCfg.pagesBinary, listeners, "", processCfg.envs, processCfg.extraArgs...)
- return logBuf, func() {
+ t.Cleanup(func() {
source.Close()
chdirCleanup()
cleanup()
- }
+ })
+
+ return logBuf
}
func RunPagesProcessWithAuth(t *testing.T, pagesBinary string, listeners []ListenSpec, promPort string) func() {
diff --git a/test/acceptance/metrics_test.go b/test/acceptance/metrics_test.go
index 56a80255..6ba147aa 100644
--- a/test/acceptance/metrics_test.go
+++ b/test/acceptance/metrics_test.go
@@ -14,11 +14,10 @@ func TestPrometheusMetricsCanBeScraped(t *testing.T) {
_, cleanup := newZipFileServerURL(t, "../../shared/pages/group/zip.gitlab.io/public.zip")
defer cleanup()
- _, teardown := RunPagesProcessWithStubGitLabServer(t,
+ RunPagesProcessWithStubGitLabServer(t,
withExtraArgument("max-conns", "10"),
withExtraArgument("metrics-address", ":42345"),
)
- defer teardown()
// need to call an actual resource to populate certain metrics e.g. gitlab_pages_domains_source_api_requests_total
res, err := GetPageFromListener(t, httpListener, "zip.gitlab.io",
diff --git a/test/acceptance/serving_test.go b/test/acceptance/serving_test.go
index 80aed7f8..92727d28 100644
--- a/test/acceptance/serving_test.go
+++ b/test/acceptance/serving_test.go
@@ -16,8 +16,7 @@ import (
func TestUnknownHostReturnsNotFound(t *testing.T) {
skipUnlessEnabled(t)
- _, teardown := RunPagesProcessWithStubGitLabServer(t)
- defer teardown()
+ RunPagesProcessWithStubGitLabServer(t)
for _, spec := range supportedListeners() {
rsp, err := GetPageFromListener(t, spec, "invalid.invalid", "")
@@ -31,8 +30,7 @@ func TestUnknownHostReturnsNotFound(t *testing.T) {
func TestUnknownProjectReturnsNotFound(t *testing.T) {
skipUnlessEnabled(t)
- _, teardown := RunPagesProcessWithStubGitLabServer(t)
- defer teardown()
+ RunPagesProcessWithStubGitLabServer(t)
rsp, err := GetPageFromListener(t, httpListener, "group.gitlab-example.com", "/nonexistent/")
require.NoError(t, err)
@@ -43,8 +41,7 @@ func TestUnknownProjectReturnsNotFound(t *testing.T) {
func TestGroupDomainReturns200(t *testing.T) {
skipUnlessEnabled(t)
- _, teardown := RunPagesProcessWithStubGitLabServer(t)
- defer teardown()
+ RunPagesProcessWithStubGitLabServer(t)
rsp, err := GetPageFromListener(t, httpListener, "group.gitlab-example.com", "/")
require.NoError(t, err)
@@ -60,8 +57,7 @@ func TestGroupDomainReturns200(t *testing.T) {
func TestKnownHostReturns200(t *testing.T) {
skipUnlessEnabled(t)
- _, teardown := RunPagesProcessWithStubGitLabServer(t)
- defer teardown()
+ RunPagesProcessWithStubGitLabServer(t)
tests := []struct {
name string
@@ -230,8 +226,7 @@ func TestCustom404(t *testing.T) {
func TestCORSWhenDisabled(t *testing.T) {
skipUnlessEnabled(t)
- _, teardown := RunPagesProcessWithStubGitLabServer(t, withExtraArgument("disable-cross-origin-requests", "true"))
- defer teardown()
+ RunPagesProcessWithStubGitLabServer(t, withExtraArgument("disable-cross-origin-requests", "true"))
for _, spec := range supportedListeners() {
for _, method := range []string{"GET", "OPTIONS"} {
@@ -247,8 +242,7 @@ func TestCORSWhenDisabled(t *testing.T) {
func TestCORSAllowsGET(t *testing.T) {
skipUnlessEnabled(t)
- _, teardown := RunPagesProcessWithStubGitLabServer(t)
- defer teardown()
+ RunPagesProcessWithStubGitLabServer(t)
for _, spec := range supportedListeners() {
for _, method := range []string{"GET", "OPTIONS"} {
@@ -264,8 +258,7 @@ func TestCORSAllowsGET(t *testing.T) {
func TestCORSForbidsPOST(t *testing.T) {
skipUnlessEnabled(t)
- _, teardown := RunPagesProcessWithStubGitLabServer(t)
- defer teardown()
+ RunPagesProcessWithStubGitLabServer(t)
for _, spec := range supportedListeners() {
rsp := doCrossOriginRequest(t, spec, "OPTIONS", "POST", spec.URL("project/"))
@@ -279,11 +272,10 @@ func TestCORSForbidsPOST(t *testing.T) {
func TestCustomHeaders(t *testing.T) {
skipUnlessEnabled(t)
- _, teardown := RunPagesProcessWithStubGitLabServer(t,
+ RunPagesProcessWithStubGitLabServer(t,
withExtraArgument("header", "X-Test1:Testing1"),
withExtraArgument("header", "X-Test2:Testing2"),
)
- defer teardown()
for _, spec := range supportedListeners() {
rsp, err := GetPageFromListener(t, spec, "group.gitlab-example.com:", "project/")
@@ -297,8 +289,7 @@ func TestCustomHeaders(t *testing.T) {
func TestKnownHostWithPortReturns200(t *testing.T) {
skipUnlessEnabled(t)
- _, teardown := RunPagesProcessWithStubGitLabServer(t)
- defer teardown()
+ RunPagesProcessWithStubGitLabServer(t)
for _, spec := range supportedListeners() {
rsp, err := GetPageFromListener(t, spec, "group.gitlab-example.com:"+spec.Port, "project/")
@@ -312,8 +303,7 @@ func TestKnownHostWithPortReturns200(t *testing.T) {
func TestHttpToHttpsRedirectDisabled(t *testing.T) {
skipUnlessEnabled(t)
- _, teardown := RunPagesProcessWithStubGitLabServer(t)
- defer teardown()
+ RunPagesProcessWithStubGitLabServer(t)
rsp, err := GetRedirectPage(t, httpListener, "group.gitlab-example.com", "project/")
require.NoError(t, err)
@@ -329,8 +319,7 @@ func TestHttpToHttpsRedirectDisabled(t *testing.T) {
func TestHttpToHttpsRedirectEnabled(t *testing.T) {
skipUnlessEnabled(t)
- _, teardown := RunPagesProcessWithStubGitLabServer(t, withExtraArgument("redirect-http", "true"))
- defer teardown()
+ RunPagesProcessWithStubGitLabServer(t, withExtraArgument("redirect-http", "true"))
rsp, err := GetRedirectPage(t, httpListener, "group.gitlab-example.com", "project/")
require.NoError(t, err)
@@ -591,8 +580,7 @@ func TestGitLabSourceBecomesUnauthorized(t *testing.T) {
func TestKnownHostInReverseProxySetupReturns200(t *testing.T) {
skipUnlessEnabled(t)
- _, teardown := RunPagesProcessWithStubGitLabServer(t)
- defer teardown()
+ RunPagesProcessWithStubGitLabServer(t)
rsp, err := GetProxiedPageFromListener(t, proxyListener, "localhost", "group.gitlab-example.com", "project/")
@@ -698,8 +686,7 @@ func doCrossOriginRequest(t *testing.T, spec ListenSpec, method, reqMethod, url
func TestQueryStringPersistedInSlashRewrite(t *testing.T) {
skipUnlessEnabled(t)
- _, teardown := RunPagesProcessWithStubGitLabServer(t)
- defer teardown()
+ RunPagesProcessWithStubGitLabServer(t)
rsp, err := GetRedirectPage(t, httpsListener, "group.gitlab-example.com", "project?q=test")
require.NoError(t, err)
@@ -735,12 +722,11 @@ func TestServerRepliesWithHeaders(t *testing.T) {
for name, test := range tests {
testFn := func(envArgs, headerArgs []string) func(*testing.T) {
return func(t *testing.T) {
- _, teardown := RunPagesProcessWithStubGitLabServer(t,
+ RunPagesProcessWithStubGitLabServer(t,
withListeners([]ListenSpec{httpListener}),
withEnv(envArgs),
withArguments(headerArgs),
)
- defer teardown()
rsp, err := GetPageFromListener(t, httpListener, "group.gitlab-example.com", "/")
require.NoError(t, err)
@@ -785,10 +771,9 @@ func TestServerRepliesWithHeaders(t *testing.T) {
func TestDiskDisabledFailsToServeFileAndLocalContent(t *testing.T) {
skipUnlessEnabled(t)
- logBuf, teardown := RunPagesProcessWithStubGitLabServer(t,
+ logBuf := RunPagesProcessWithStubGitLabServer(t,
withExtraArgument("enable-disk", "false"),
)
- defer teardown()
for host, suffix := range map[string]string{
// API serves "source": { "type": "local" }