diff --git a/cmd/serve/s3/s3_test.go b/cmd/serve/s3/s3_test.go index 83186df536809..5043179fbd07e 100644 --- a/cmd/serve/s3/s3_test.go +++ b/cmd/serve/s3/s3_test.go @@ -9,11 +9,8 @@ import ( "fmt" "io" "net/url" - "os" - "os/exec" "path" "path/filepath" - "strings" "testing" "time" @@ -78,81 +75,7 @@ func TestS3(t *testing.T) { return config, func() {} } - fstest.Initialise() - t.Run("Normal", func(t *testing.T) { - runServeTests(t, "s3", start, false) - }) - t.Run("AuthProxy", func(t *testing.T) { - runServeTests(t, "s3", start, true) - }) -} - -func runServeTests(t *testing.T, name string, start servetest.StartFn, useProxy bool) { - ci := fs.GetConfig(context.Background()) - ci.DisableFeatures = append(ci.DisableFeatures, "Metadata") - - fremote, _, clean, err := fstest.RandomRemote() - assert.NoError(t, err) - defer clean() - - err = fremote.Mkdir(context.Background(), "") - assert.NoError(t, err) - - f := fremote - if useProxy { - // If using a proxy don't pass in the backend - f = nil - - // the backend config will be made by the proxy - prog, err := filepath.Abs("../servetest/proxy_code.go") - require.NoError(t, err) - cmd := "go run " + prog + " " + fremote.Root() - - // FIXME this is untidy setting a global variable! - proxyflags.Opt.AuthProxy = cmd - defer func() { - proxyflags.Opt.AuthProxy = "" - }() - } - config, cleanup := start(f) - defer cleanup() - - // Change directory to run the tests - cwd, err := os.Getwd() - require.NoError(t, err) - err = os.Chdir("../../../backend/" + name) - require.NoError(t, err, "failed to cd to "+name+" backend") - defer func() { - // Change back to the old directory - require.NoError(t, os.Chdir(cwd)) - }() - - // RunS3UnitTests the backend tests with an on the fly remote - args := []string{"test"} - if testing.Verbose() { - args = append(args, "-v") - } - if *fstest.Verbose { - args = append(args, "-verbose") - } - remoteName := "serve" + name + ":" - args = append(args, "-remote", remoteName) - args = append(args, "-list-retries", fmt.Sprint(*fstest.ListRetries)) - cmd := exec.Command("go", args...) - - // Configure the backend with environment variables - cmd.Env = os.Environ() - prefix := "RCLONE_CONFIG_" + strings.ToUpper(remoteName[:len(remoteName)-1]) + "_" - for k, v := range config { - cmd.Env = append(cmd.Env, prefix+strings.ToUpper(k)+"="+v) - } - - // RunS3UnitTests the test - out, err := cmd.CombinedOutput() - if len(out) != 0 { - t.Logf("\n----------\n%s----------\n", string(out)) - } - assert.NoError(t, err, "Running "+name+" integration tests") + servetest.Run(t, "s3", start) } // tests using the minio client diff --git a/cmd/serve/servetest/servetest.go b/cmd/serve/servetest/servetest.go index f0f24633514f5..b11a016276ccf 100644 --- a/cmd/serve/servetest/servetest.go +++ b/cmd/serve/servetest/servetest.go @@ -76,7 +76,7 @@ func run(t *testing.T, name string, start StartFn, useProxy bool) { if *fstest.Verbose { args = append(args, "-verbose") } - remoteName := name + "test:" + remoteName := "serve" + name + "test:" if *subRun != "" { args = append(args, "-run", *subRun) }