Skip to content

Commit

Permalink
refactor: rename remote name and run tests from servertest
Browse files Browse the repository at this point in the history
  • Loading branch information
saw-jan committed Jul 17, 2024
1 parent df51fc3 commit d265801
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 79 deletions.
79 changes: 1 addition & 78 deletions cmd/serve/s3/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ import (
"fmt"
"io"
"net/url"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/serve/servetest/servetest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit d265801

Please sign in to comment.