2016-10-11 04:33:17 +00:00
|
|
|
/*
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
Copyright 2016 The Perkeep Authors
|
2016-10-11 04:33:17 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package b2
|
|
|
|
|
|
|
|
import (
|
2017-11-26 09:05:38 +00:00
|
|
|
"context"
|
2016-10-11 04:33:17 +00:00
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"math/rand"
|
|
|
|
"path"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
"perkeep.org/pkg/blob"
|
|
|
|
"perkeep.org/pkg/blobserver"
|
|
|
|
"perkeep.org/pkg/blobserver/storagetest"
|
2016-10-11 04:33:17 +00:00
|
|
|
|
|
|
|
"go4.org/jsonconfig"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
accountID = flag.String("account-id", "", "B2 Account ID for testing")
|
|
|
|
appKey = flag.String("application-key", "", "B2 Application Key for testing")
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStorage(t *testing.T) {
|
|
|
|
testStorage(t, "")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStorageWithBucketDir(t *testing.T) {
|
|
|
|
testStorage(t, "/bl/obs/")
|
|
|
|
}
|
|
|
|
|
|
|
|
func testStorage(t *testing.T, bucketDir string) {
|
2018-01-19 17:19:02 +00:00
|
|
|
ctx := context.Background()
|
2016-10-11 04:33:17 +00:00
|
|
|
if *accountID == "" && *appKey == "" {
|
|
|
|
t.Skip("Skipping test without --account-id or --application-key flag")
|
|
|
|
}
|
|
|
|
|
|
|
|
rn := rand.New(rand.NewSource(time.Now().UnixNano())).Intn(1000000)
|
|
|
|
bucket := fmt.Sprintf("camli-test-%d", rn)
|
|
|
|
bucketWithDir := path.Join(bucket, bucketDir)
|
|
|
|
|
|
|
|
storagetest.TestOpt(t, storagetest.Opts{
|
|
|
|
New: func(t *testing.T) (sto blobserver.Storage, cleanup func()) {
|
|
|
|
sto, err := newFromConfig(nil, jsonconfig.Obj{
|
|
|
|
"bucket": bucketWithDir,
|
|
|
|
"auth": map[string]interface{}{
|
|
|
|
"account_id": *accountID,
|
|
|
|
"application_key": *appKey,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if !testing.Short() {
|
|
|
|
log.Printf("Warning: this test does many serial operations. Without the go test -short flag, this test will be very slow.")
|
|
|
|
}
|
|
|
|
if bucketWithDir != bucket {
|
|
|
|
// Adding "a", and "c" objects in the bucket to make sure objects out of the
|
|
|
|
// "directory" are not touched and have no influence.
|
|
|
|
for _, key := range []string{"a", "c"} {
|
|
|
|
if _, err := sto.(*Storage).b.Upload(strings.NewReader(key), key, ""); err != nil {
|
|
|
|
t.Fatalf("could not insert object %s in bucket %v: %v", key, sto.(*Storage).b.Name, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clearBucket := func(beforeTests bool) func() {
|
|
|
|
return func() {
|
|
|
|
var all []blob.Ref
|
2018-01-19 17:19:02 +00:00
|
|
|
blobserver.EnumerateAll(ctx, sto, func(sb blob.SizedRef) error {
|
2016-10-11 04:33:17 +00:00
|
|
|
t.Logf("Deleting: %v", sb.Ref)
|
|
|
|
all = append(all, sb.Ref)
|
|
|
|
return nil
|
|
|
|
})
|
2018-01-19 17:19:02 +00:00
|
|
|
if err := sto.RemoveBlobs(ctx, all); err != nil {
|
2016-10-11 04:33:17 +00:00
|
|
|
t.Fatalf("Error removing blobs during cleanup: %v", err)
|
|
|
|
}
|
|
|
|
if beforeTests {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if bucketWithDir != bucket {
|
|
|
|
// checking that "a" and "c" at the root were left untouched.
|
|
|
|
for _, key := range []string{"a", "c"} {
|
|
|
|
fi, err := sto.(*Storage).b.GetFileInfoByName(key)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not remove object %s after tests: %v", key, err)
|
|
|
|
}
|
|
|
|
if err := sto.(*Storage).cl.DeleteFile(fi.ID, fi.Name); err != nil {
|
|
|
|
t.Fatalf("could not remove object %s after tests: %v", key, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := sto.(*Storage).b.Delete(); err != nil {
|
2018-01-19 17:19:02 +00:00
|
|
|
t.Fatalf("could not remove5D bucket %s after tests: %v", sto.(*Storage).b.Name, err)
|
2016-10-11 04:33:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
clearBucket(true)()
|
|
|
|
return sto, clearBucket(false)
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|