2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-17 02:25:12 +00:00
restic/internal/backend/swift/swift_test.go

78 lines
1.7 KiB
Go
Raw Normal View History

package swift_test
import (
"fmt"
2017-05-01 08:13:03 +00:00
"os"
"testing"
"time"
"github.com/restic/restic/internal/backend"
2017-07-23 12:21:03 +00:00
"github.com/restic/restic/internal/backend/swift"
"github.com/restic/restic/internal/backend/test"
2017-10-02 13:06:39 +00:00
rtest "github.com/restic/restic/internal/test"
)
func newSwiftTestSuite(t testing.TB) *test.Suite[swift.Config] {
return &test.Suite[swift.Config]{
2017-05-01 08:13:03 +00:00
// do not use excessive data
MinimalData: true,
// wait for removals for at least 5m
WaitForDelayedRemoval: 5 * time.Minute,
ErrorHandler: func(t testing.TB, be backend.Backend, err error) error {
if err == nil {
return nil
}
if be.IsNotExist(err) {
t.Logf("swift: ignoring error %v", err)
return nil
}
return err
},
2017-05-01 08:13:03 +00:00
// NewConfig returns a config for a new temporary backend that will be used in tests.
NewConfig: func() (*swift.Config, error) {
cfg, err := swift.ParseConfig(os.Getenv("RESTIC_TEST_SWIFT"))
2017-05-01 08:13:03 +00:00
if err != nil {
return nil, err
2017-05-01 08:13:03 +00:00
}
cfg.ApplyEnvironment("RESTIC_TEST_")
2017-05-01 08:13:03 +00:00
cfg.Prefix += fmt.Sprintf("/test-%d", time.Now().UnixNano())
t.Logf("using prefix %v", cfg.Prefix)
return cfg, nil
},
Factory: swift.NewFactory(),
}
2017-05-01 08:13:03 +00:00
}
2017-05-01 08:13:03 +00:00
func TestBackendSwift(t *testing.T) {
defer func() {
if t.Skipped() {
2017-10-02 13:06:39 +00:00
rtest.SkipDisallowed(t, "restic/backend/swift.TestBackendSwift")
}
2017-05-01 08:13:03 +00:00
}()
if os.Getenv("RESTIC_TEST_SWIFT") == "" {
t.Skip("RESTIC_TEST_SWIFT unset, skipping test")
return
}
2017-05-01 08:13:03 +00:00
t.Logf("run tests")
newSwiftTestSuite(t).RunTests(t)
}
func BenchmarkBackendSwift(t *testing.B) {
if os.Getenv("RESTIC_TEST_SWIFT") == "" {
t.Skip("RESTIC_TEST_SWIFT unset, skipping test")
return
}
t.Logf("run tests")
newSwiftTestSuite(t).RunBenchmarks(t)
}