2017-05-28 08:19:01 +00:00
|
|
|
package b2_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2017-07-23 12:21:03 +00:00
|
|
|
"github.com/restic/restic/internal/backend/b2"
|
|
|
|
"github.com/restic/restic/internal/backend/test"
|
2017-05-28 08:19:01 +00:00
|
|
|
|
2017-10-02 13:06:39 +00:00
|
|
|
rtest "github.com/restic/restic/internal/test"
|
2017-05-28 08:19:01 +00:00
|
|
|
)
|
|
|
|
|
2023-06-08 17:35:20 +00:00
|
|
|
func newB2TestSuite() *test.Suite[b2.Config] {
|
2023-04-21 19:06:56 +00:00
|
|
|
return &test.Suite[b2.Config]{
|
2017-05-28 08:19:01 +00:00
|
|
|
// do not use excessive data
|
|
|
|
MinimalData: true,
|
|
|
|
|
2017-06-18 15:36:57 +00:00
|
|
|
// wait for at most 10 seconds for removed files to disappear
|
|
|
|
WaitForDelayedRemoval: 10 * time.Second,
|
|
|
|
|
2017-05-28 08:19:01 +00:00
|
|
|
// NewConfig returns a config for a new temporary backend that will be used in tests.
|
2023-04-21 19:35:34 +00:00
|
|
|
NewConfig: func() (*b2.Config, error) {
|
2023-04-20 20:40:21 +00:00
|
|
|
cfg, err := b2.ParseConfig(os.Getenv("RESTIC_TEST_B2_REPOSITORY"))
|
2017-05-28 08:19:01 +00:00
|
|
|
if err != nil {
|
2023-04-21 19:35:34 +00:00
|
|
|
return nil, err
|
2017-05-28 08:19:01 +00:00
|
|
|
}
|
|
|
|
|
2023-06-08 13:28:07 +00:00
|
|
|
cfg.ApplyEnvironment("RESTIC_TEST_")
|
2017-05-28 08:19:01 +00:00
|
|
|
cfg.Prefix = fmt.Sprintf("test-%d", time.Now().UnixNano())
|
|
|
|
return cfg, nil
|
|
|
|
},
|
|
|
|
|
2023-06-08 14:53:55 +00:00
|
|
|
Factory: b2.NewFactory(),
|
2017-05-28 08:19:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func testVars(t testing.TB) {
|
|
|
|
vars := []string{
|
|
|
|
"RESTIC_TEST_B2_ACCOUNT_ID",
|
|
|
|
"RESTIC_TEST_B2_ACCOUNT_KEY",
|
|
|
|
"RESTIC_TEST_B2_REPOSITORY",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range vars {
|
|
|
|
if os.Getenv(v) == "" {
|
|
|
|
t.Skipf("environment variable %v not set", v)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBackendB2(t *testing.T) {
|
|
|
|
defer func() {
|
|
|
|
if t.Skipped() {
|
2017-10-02 13:06:39 +00:00
|
|
|
rtest.SkipDisallowed(t, "restic/backend/b2.TestBackendB2")
|
2017-05-28 08:19:01 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
testVars(t)
|
2023-06-08 17:35:20 +00:00
|
|
|
newB2TestSuite().RunTests(t)
|
2017-05-28 08:19:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkBackendb2(t *testing.B) {
|
|
|
|
testVars(t)
|
2023-06-08 17:35:20 +00:00
|
|
|
newB2TestSuite().RunBenchmarks(t)
|
2017-05-28 08:19:01 +00:00
|
|
|
}
|