perkeep/pkg/googlestorage/googlestorage_test.go

225 lines
6.1 KiB
Go
Raw Normal View History

/*
Copyright 2011 Google Inc.
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.
*/
// FYI These tests are integration tests that need to run against google
// storage. See the README for more details on necessary setup
package googlestorage
import (
"bytes"
"fmt"
Add SKIP_DEP_TESTS env var to skip tests with depdendencies. Now all tests pass like this: bradmac-2:camlistore.org $ SKIP_DEP_TESTS=1 go test ./pkg/... ? camlistore.org/pkg/auth [no test files] ok camlistore.org/pkg/blobref 0.023s ok camlistore.org/pkg/blobserver 0.032s ? camlistore.org/pkg/blobserver/cond [no test files] ? camlistore.org/pkg/blobserver/google [no test files] ok camlistore.org/pkg/blobserver/handlers 0.031s ok camlistore.org/pkg/blobserver/localdisk 1.693s ? camlistore.org/pkg/blobserver/remote [no test files] ? camlistore.org/pkg/blobserver/replica [no test files] ? camlistore.org/pkg/blobserver/s3 [no test files] ? camlistore.org/pkg/blobserver/shard [no test files] ? camlistore.org/pkg/cacher [no test files] ok camlistore.org/pkg/client 0.029s ? camlistore.org/pkg/errorutil [no test files] ? camlistore.org/pkg/fileembed [no test files] ? camlistore.org/pkg/fileembed/genfileembed [no test files] ? camlistore.org/pkg/fs [no test files] ok camlistore.org/pkg/googlestorage 0.034s ? camlistore.org/pkg/httputil [no test files] ok camlistore.org/pkg/index 0.298s ? camlistore.org/pkg/index/indextest [no test files] ok camlistore.org/pkg/index/mongo 0.524s ok camlistore.org/pkg/index/mysql 0.020s ok camlistore.org/pkg/jsonconfig 0.022s ok camlistore.org/pkg/jsonsign 0.155s ok camlistore.org/pkg/lru 0.015s ok camlistore.org/pkg/magic 0.030s ? camlistore.org/pkg/misc [no test files] ok camlistore.org/pkg/misc/amazon/s3 0.028s ok camlistore.org/pkg/misc/gpgagent 0.018s ok camlistore.org/pkg/misc/httprange 0.026s ? camlistore.org/pkg/misc/pinentry [no test files] ? camlistore.org/pkg/misc/resize [no test files] ok camlistore.org/pkg/netutil 0.088s ok camlistore.org/pkg/osutil 0.016s ok camlistore.org/pkg/rollsum 0.027s ok camlistore.org/pkg/schema 0.017s ok camlistore.org/pkg/search 0.016s ok camlistore.org/pkg/server 0.039s ok camlistore.org/pkg/serverconfig 0.031s ? camlistore.org/pkg/test [no test files] ? camlistore.org/pkg/test/asserts [no test files] ? camlistore.org/pkg/test/testdep [no test files] ? camlistore.org/pkg/webserver [no test files] Change-Id: I9c9b0ee4f51cbcf785aed665bbb494339dd84261
2012-03-30 01:21:37 +00:00
"os"
"testing"
"time"
"camlistore.org/pkg/jsonconfig"
Add SKIP_DEP_TESTS env var to skip tests with depdendencies. Now all tests pass like this: bradmac-2:camlistore.org $ SKIP_DEP_TESTS=1 go test ./pkg/... ? camlistore.org/pkg/auth [no test files] ok camlistore.org/pkg/blobref 0.023s ok camlistore.org/pkg/blobserver 0.032s ? camlistore.org/pkg/blobserver/cond [no test files] ? camlistore.org/pkg/blobserver/google [no test files] ok camlistore.org/pkg/blobserver/handlers 0.031s ok camlistore.org/pkg/blobserver/localdisk 1.693s ? camlistore.org/pkg/blobserver/remote [no test files] ? camlistore.org/pkg/blobserver/replica [no test files] ? camlistore.org/pkg/blobserver/s3 [no test files] ? camlistore.org/pkg/blobserver/shard [no test files] ? camlistore.org/pkg/cacher [no test files] ok camlistore.org/pkg/client 0.029s ? camlistore.org/pkg/errorutil [no test files] ? camlistore.org/pkg/fileembed [no test files] ? camlistore.org/pkg/fileembed/genfileembed [no test files] ? camlistore.org/pkg/fs [no test files] ok camlistore.org/pkg/googlestorage 0.034s ? camlistore.org/pkg/httputil [no test files] ok camlistore.org/pkg/index 0.298s ? camlistore.org/pkg/index/indextest [no test files] ok camlistore.org/pkg/index/mongo 0.524s ok camlistore.org/pkg/index/mysql 0.020s ok camlistore.org/pkg/jsonconfig 0.022s ok camlistore.org/pkg/jsonsign 0.155s ok camlistore.org/pkg/lru 0.015s ok camlistore.org/pkg/magic 0.030s ? camlistore.org/pkg/misc [no test files] ok camlistore.org/pkg/misc/amazon/s3 0.028s ok camlistore.org/pkg/misc/gpgagent 0.018s ok camlistore.org/pkg/misc/httprange 0.026s ? camlistore.org/pkg/misc/pinentry [no test files] ? camlistore.org/pkg/misc/resize [no test files] ok camlistore.org/pkg/netutil 0.088s ok camlistore.org/pkg/osutil 0.016s ok camlistore.org/pkg/rollsum 0.027s ok camlistore.org/pkg/schema 0.017s ok camlistore.org/pkg/search 0.016s ok camlistore.org/pkg/server 0.039s ok camlistore.org/pkg/serverconfig 0.031s ? camlistore.org/pkg/test [no test files] ? camlistore.org/pkg/test/asserts [no test files] ? camlistore.org/pkg/test/testdep [no test files] ? camlistore.org/pkg/webserver [no test files] Change-Id: I9c9b0ee4f51cbcf785aed665bbb494339dd84261
2012-03-30 01:21:37 +00:00
"camlistore.org/pkg/test/testdep"
"camlistore.org/third_party/code.google.com/p/goauth2/oauth"
)
const testObjectContent = "Google Storage Test\n"
type BufferCloser struct {
*bytes.Buffer
}
func (b *BufferCloser) Close() error {
b.Reset()
return nil
}
// Reads google storage config and creates a Client. Exits on error.
func doConfig(t *testing.T) (gsa *Client, bucket string) {
Add SKIP_DEP_TESTS env var to skip tests with depdendencies. Now all tests pass like this: bradmac-2:camlistore.org $ SKIP_DEP_TESTS=1 go test ./pkg/... ? camlistore.org/pkg/auth [no test files] ok camlistore.org/pkg/blobref 0.023s ok camlistore.org/pkg/blobserver 0.032s ? camlistore.org/pkg/blobserver/cond [no test files] ? camlistore.org/pkg/blobserver/google [no test files] ok camlistore.org/pkg/blobserver/handlers 0.031s ok camlistore.org/pkg/blobserver/localdisk 1.693s ? camlistore.org/pkg/blobserver/remote [no test files] ? camlistore.org/pkg/blobserver/replica [no test files] ? camlistore.org/pkg/blobserver/s3 [no test files] ? camlistore.org/pkg/blobserver/shard [no test files] ? camlistore.org/pkg/cacher [no test files] ok camlistore.org/pkg/client 0.029s ? camlistore.org/pkg/errorutil [no test files] ? camlistore.org/pkg/fileembed [no test files] ? camlistore.org/pkg/fileembed/genfileembed [no test files] ? camlistore.org/pkg/fs [no test files] ok camlistore.org/pkg/googlestorage 0.034s ? camlistore.org/pkg/httputil [no test files] ok camlistore.org/pkg/index 0.298s ? camlistore.org/pkg/index/indextest [no test files] ok camlistore.org/pkg/index/mongo 0.524s ok camlistore.org/pkg/index/mysql 0.020s ok camlistore.org/pkg/jsonconfig 0.022s ok camlistore.org/pkg/jsonsign 0.155s ok camlistore.org/pkg/lru 0.015s ok camlistore.org/pkg/magic 0.030s ? camlistore.org/pkg/misc [no test files] ok camlistore.org/pkg/misc/amazon/s3 0.028s ok camlistore.org/pkg/misc/gpgagent 0.018s ok camlistore.org/pkg/misc/httprange 0.026s ? camlistore.org/pkg/misc/pinentry [no test files] ? camlistore.org/pkg/misc/resize [no test files] ok camlistore.org/pkg/netutil 0.088s ok camlistore.org/pkg/osutil 0.016s ok camlistore.org/pkg/rollsum 0.027s ok camlistore.org/pkg/schema 0.017s ok camlistore.org/pkg/search 0.016s ok camlistore.org/pkg/server 0.039s ok camlistore.org/pkg/serverconfig 0.031s ? camlistore.org/pkg/test [no test files] ? camlistore.org/pkg/test/asserts [no test files] ? camlistore.org/pkg/test/testdep [no test files] ? camlistore.org/pkg/webserver [no test files] Change-Id: I9c9b0ee4f51cbcf785aed665bbb494339dd84261
2012-03-30 01:21:37 +00:00
if _, err := os.Stat("gstestconfig.json"); os.IsNotExist(err) {
testdep.CheckEnv(t)
t.Fatalf("Missing config file: %v", err)
}
cf, err := jsonconfig.ReadFile("testconfig.json")
if err != nil {
t.Fatalf("Failed to read config: %v", err)
}
var config jsonconfig.Obj
config = cf.RequiredObject("gsconf")
if err := cf.Validate(); err != nil {
t.Fatalf("Invalid config: %v", err)
}
auth := config.RequiredObject("auth")
bucket = config.RequiredString("bucket")
if err := config.Validate(); err != nil {
t.Fatalf("Invalid config: %v", err)
}
gsa = NewClient(&oauth.Transport{
&oauth.Config{
ClientId: auth.RequiredString("client_id"),
ClientSecret: auth.RequiredString("client_secret"),
Scope: "https://www.googleapis.com/auth/devstorage.read_write",
AuthURL: "https://accounts.google.com/o/oauth2/auth",
TokenURL: "https://accounts.google.com/o/oauth2/token",
RedirectURL: "urn:ietf:wg:oauth:2.0:oob",
},
&oauth.Token{
AccessToken: "",
RefreshToken: auth.RequiredString("refresh_token"),
},
nil,
})
if err := auth.Validate(); err != nil {
t.Fatalf("Invalid config: %v", err)
}
return
}
func TestGetObject(t *testing.T) {
gs, bucket := doConfig(t)
body, size, err := gs.GetObject(&Object{bucket, "test-get"})
if err != nil {
t.Fatalf("Fetch failed: %v\n", err)
}
content := make([]byte, size)
if _, err = body.Read(content); err != nil {
t.Fatalf("Failed to read response body: %v:\n", err)
}
if string(content) != testObjectContent {
t.Fatalf("Object has incorrect content.\nExpected: '%v'\nFound: '%v'\n", testObjectContent, string(content))
}
}
func TestStatObject(t *testing.T) {
gs, bucket := doConfig(t)
// Stat a nonexistant file
size, exists, err := gs.StatObject(&Object{bucket, "test-shouldntexist"})
if err != nil {
t.Errorf("Stat failed: %v\n", err)
}
if exists {
t.Errorf("Test object exists!")
}
if size != 0 {
t.Errorf("Expected size to be 0, found %v\n", size)
}
// Try statting an object which does exist
size, exists, err = gs.StatObject(&Object{bucket, "test-stat"})
if err != nil {
t.Errorf("Stat failed: %v\n", err)
}
if !exists {
t.Errorf("Test object doesn't exist!")
}
if size != int64(len(testObjectContent)) {
t.Errorf("Test object size is wrong: \nexpected: %v\nfound: %v\n",
len(testObjectContent), size)
}
}
func TestPutObject(t *testing.T) {
gs, bucket := doConfig(t)
Add SKIP_DEP_TESTS env var to skip tests with depdendencies. Now all tests pass like this: bradmac-2:camlistore.org $ SKIP_DEP_TESTS=1 go test ./pkg/... ? camlistore.org/pkg/auth [no test files] ok camlistore.org/pkg/blobref 0.023s ok camlistore.org/pkg/blobserver 0.032s ? camlistore.org/pkg/blobserver/cond [no test files] ? camlistore.org/pkg/blobserver/google [no test files] ok camlistore.org/pkg/blobserver/handlers 0.031s ok camlistore.org/pkg/blobserver/localdisk 1.693s ? camlistore.org/pkg/blobserver/remote [no test files] ? camlistore.org/pkg/blobserver/replica [no test files] ? camlistore.org/pkg/blobserver/s3 [no test files] ? camlistore.org/pkg/blobserver/shard [no test files] ? camlistore.org/pkg/cacher [no test files] ok camlistore.org/pkg/client 0.029s ? camlistore.org/pkg/errorutil [no test files] ? camlistore.org/pkg/fileembed [no test files] ? camlistore.org/pkg/fileembed/genfileembed [no test files] ? camlistore.org/pkg/fs [no test files] ok camlistore.org/pkg/googlestorage 0.034s ? camlistore.org/pkg/httputil [no test files] ok camlistore.org/pkg/index 0.298s ? camlistore.org/pkg/index/indextest [no test files] ok camlistore.org/pkg/index/mongo 0.524s ok camlistore.org/pkg/index/mysql 0.020s ok camlistore.org/pkg/jsonconfig 0.022s ok camlistore.org/pkg/jsonsign 0.155s ok camlistore.org/pkg/lru 0.015s ok camlistore.org/pkg/magic 0.030s ? camlistore.org/pkg/misc [no test files] ok camlistore.org/pkg/misc/amazon/s3 0.028s ok camlistore.org/pkg/misc/gpgagent 0.018s ok camlistore.org/pkg/misc/httprange 0.026s ? camlistore.org/pkg/misc/pinentry [no test files] ? camlistore.org/pkg/misc/resize [no test files] ok camlistore.org/pkg/netutil 0.088s ok camlistore.org/pkg/osutil 0.016s ok camlistore.org/pkg/rollsum 0.027s ok camlistore.org/pkg/schema 0.017s ok camlistore.org/pkg/search 0.016s ok camlistore.org/pkg/server 0.039s ok camlistore.org/pkg/serverconfig 0.031s ? camlistore.org/pkg/test [no test files] ? camlistore.org/pkg/test/asserts [no test files] ? camlistore.org/pkg/test/testdep [no test files] ? camlistore.org/pkg/webserver [no test files] Change-Id: I9c9b0ee4f51cbcf785aed665bbb494339dd84261
2012-03-30 01:21:37 +00:00
now := time.Now()
testKey := fmt.Sprintf("test-put-%v.%v.%v-%v.%v.%v",
Add SKIP_DEP_TESTS env var to skip tests with depdendencies. Now all tests pass like this: bradmac-2:camlistore.org $ SKIP_DEP_TESTS=1 go test ./pkg/... ? camlistore.org/pkg/auth [no test files] ok camlistore.org/pkg/blobref 0.023s ok camlistore.org/pkg/blobserver 0.032s ? camlistore.org/pkg/blobserver/cond [no test files] ? camlistore.org/pkg/blobserver/google [no test files] ok camlistore.org/pkg/blobserver/handlers 0.031s ok camlistore.org/pkg/blobserver/localdisk 1.693s ? camlistore.org/pkg/blobserver/remote [no test files] ? camlistore.org/pkg/blobserver/replica [no test files] ? camlistore.org/pkg/blobserver/s3 [no test files] ? camlistore.org/pkg/blobserver/shard [no test files] ? camlistore.org/pkg/cacher [no test files] ok camlistore.org/pkg/client 0.029s ? camlistore.org/pkg/errorutil [no test files] ? camlistore.org/pkg/fileembed [no test files] ? camlistore.org/pkg/fileembed/genfileembed [no test files] ? camlistore.org/pkg/fs [no test files] ok camlistore.org/pkg/googlestorage 0.034s ? camlistore.org/pkg/httputil [no test files] ok camlistore.org/pkg/index 0.298s ? camlistore.org/pkg/index/indextest [no test files] ok camlistore.org/pkg/index/mongo 0.524s ok camlistore.org/pkg/index/mysql 0.020s ok camlistore.org/pkg/jsonconfig 0.022s ok camlistore.org/pkg/jsonsign 0.155s ok camlistore.org/pkg/lru 0.015s ok camlistore.org/pkg/magic 0.030s ? camlistore.org/pkg/misc [no test files] ok camlistore.org/pkg/misc/amazon/s3 0.028s ok camlistore.org/pkg/misc/gpgagent 0.018s ok camlistore.org/pkg/misc/httprange 0.026s ? camlistore.org/pkg/misc/pinentry [no test files] ? camlistore.org/pkg/misc/resize [no test files] ok camlistore.org/pkg/netutil 0.088s ok camlistore.org/pkg/osutil 0.016s ok camlistore.org/pkg/rollsum 0.027s ok camlistore.org/pkg/schema 0.017s ok camlistore.org/pkg/search 0.016s ok camlistore.org/pkg/server 0.039s ok camlistore.org/pkg/serverconfig 0.031s ? camlistore.org/pkg/test [no test files] ? camlistore.org/pkg/test/asserts [no test files] ? camlistore.org/pkg/test/testdep [no test files] ? camlistore.org/pkg/webserver [no test files] Change-Id: I9c9b0ee4f51cbcf785aed665bbb494339dd84261
2012-03-30 01:21:37 +00:00
now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second())
shouldRetry, err := gs.PutObject(&Object{bucket, testKey},
&BufferCloser{bytes.NewBufferString(testObjectContent)})
if shouldRetry {
shouldRetry, err = gs.PutObject(&Object{bucket, testKey},
&BufferCloser{bytes.NewBufferString(testObjectContent)})
}
if err != nil {
t.Fatalf("Failed to put object: %v", err)
}
// Just stat to check that it actually uploaded, don't bother reading back
size, exists, err := gs.StatObject(&Object{bucket, testKey})
if !exists {
t.Errorf("Test object doesn't exist!")
}
if size != int64(len(testObjectContent)) {
t.Errorf("Test object size is wrong: \nexpected: %v\nfound: %v\n",
len(testObjectContent), size)
}
}
func TestDeleteObject(t *testing.T) {
gs, bucket := doConfig(t)
// Try deleting a nonexitent file
err := gs.DeleteObject(&Object{bucket, "test-shouldntexist"})
if err == nil {
t.Errorf("Tried to delete nonexistent object, succeeded.")
}
// Create a file, try to delete it
Add SKIP_DEP_TESTS env var to skip tests with depdendencies. Now all tests pass like this: bradmac-2:camlistore.org $ SKIP_DEP_TESTS=1 go test ./pkg/... ? camlistore.org/pkg/auth [no test files] ok camlistore.org/pkg/blobref 0.023s ok camlistore.org/pkg/blobserver 0.032s ? camlistore.org/pkg/blobserver/cond [no test files] ? camlistore.org/pkg/blobserver/google [no test files] ok camlistore.org/pkg/blobserver/handlers 0.031s ok camlistore.org/pkg/blobserver/localdisk 1.693s ? camlistore.org/pkg/blobserver/remote [no test files] ? camlistore.org/pkg/blobserver/replica [no test files] ? camlistore.org/pkg/blobserver/s3 [no test files] ? camlistore.org/pkg/blobserver/shard [no test files] ? camlistore.org/pkg/cacher [no test files] ok camlistore.org/pkg/client 0.029s ? camlistore.org/pkg/errorutil [no test files] ? camlistore.org/pkg/fileembed [no test files] ? camlistore.org/pkg/fileembed/genfileembed [no test files] ? camlistore.org/pkg/fs [no test files] ok camlistore.org/pkg/googlestorage 0.034s ? camlistore.org/pkg/httputil [no test files] ok camlistore.org/pkg/index 0.298s ? camlistore.org/pkg/index/indextest [no test files] ok camlistore.org/pkg/index/mongo 0.524s ok camlistore.org/pkg/index/mysql 0.020s ok camlistore.org/pkg/jsonconfig 0.022s ok camlistore.org/pkg/jsonsign 0.155s ok camlistore.org/pkg/lru 0.015s ok camlistore.org/pkg/magic 0.030s ? camlistore.org/pkg/misc [no test files] ok camlistore.org/pkg/misc/amazon/s3 0.028s ok camlistore.org/pkg/misc/gpgagent 0.018s ok camlistore.org/pkg/misc/httprange 0.026s ? camlistore.org/pkg/misc/pinentry [no test files] ? camlistore.org/pkg/misc/resize [no test files] ok camlistore.org/pkg/netutil 0.088s ok camlistore.org/pkg/osutil 0.016s ok camlistore.org/pkg/rollsum 0.027s ok camlistore.org/pkg/schema 0.017s ok camlistore.org/pkg/search 0.016s ok camlistore.org/pkg/server 0.039s ok camlistore.org/pkg/serverconfig 0.031s ? camlistore.org/pkg/test [no test files] ? camlistore.org/pkg/test/asserts [no test files] ? camlistore.org/pkg/test/testdep [no test files] ? camlistore.org/pkg/webserver [no test files] Change-Id: I9c9b0ee4f51cbcf785aed665bbb494339dd84261
2012-03-30 01:21:37 +00:00
now := time.Now()
testKey := fmt.Sprintf("test-delete-%v.%v.%v-%v.%v.%v",
Add SKIP_DEP_TESTS env var to skip tests with depdendencies. Now all tests pass like this: bradmac-2:camlistore.org $ SKIP_DEP_TESTS=1 go test ./pkg/... ? camlistore.org/pkg/auth [no test files] ok camlistore.org/pkg/blobref 0.023s ok camlistore.org/pkg/blobserver 0.032s ? camlistore.org/pkg/blobserver/cond [no test files] ? camlistore.org/pkg/blobserver/google [no test files] ok camlistore.org/pkg/blobserver/handlers 0.031s ok camlistore.org/pkg/blobserver/localdisk 1.693s ? camlistore.org/pkg/blobserver/remote [no test files] ? camlistore.org/pkg/blobserver/replica [no test files] ? camlistore.org/pkg/blobserver/s3 [no test files] ? camlistore.org/pkg/blobserver/shard [no test files] ? camlistore.org/pkg/cacher [no test files] ok camlistore.org/pkg/client 0.029s ? camlistore.org/pkg/errorutil [no test files] ? camlistore.org/pkg/fileembed [no test files] ? camlistore.org/pkg/fileembed/genfileembed [no test files] ? camlistore.org/pkg/fs [no test files] ok camlistore.org/pkg/googlestorage 0.034s ? camlistore.org/pkg/httputil [no test files] ok camlistore.org/pkg/index 0.298s ? camlistore.org/pkg/index/indextest [no test files] ok camlistore.org/pkg/index/mongo 0.524s ok camlistore.org/pkg/index/mysql 0.020s ok camlistore.org/pkg/jsonconfig 0.022s ok camlistore.org/pkg/jsonsign 0.155s ok camlistore.org/pkg/lru 0.015s ok camlistore.org/pkg/magic 0.030s ? camlistore.org/pkg/misc [no test files] ok camlistore.org/pkg/misc/amazon/s3 0.028s ok camlistore.org/pkg/misc/gpgagent 0.018s ok camlistore.org/pkg/misc/httprange 0.026s ? camlistore.org/pkg/misc/pinentry [no test files] ? camlistore.org/pkg/misc/resize [no test files] ok camlistore.org/pkg/netutil 0.088s ok camlistore.org/pkg/osutil 0.016s ok camlistore.org/pkg/rollsum 0.027s ok camlistore.org/pkg/schema 0.017s ok camlistore.org/pkg/search 0.016s ok camlistore.org/pkg/server 0.039s ok camlistore.org/pkg/serverconfig 0.031s ? camlistore.org/pkg/test [no test files] ? camlistore.org/pkg/test/asserts [no test files] ? camlistore.org/pkg/test/testdep [no test files] ? camlistore.org/pkg/webserver [no test files] Change-Id: I9c9b0ee4f51cbcf785aed665bbb494339dd84261
2012-03-30 01:21:37 +00:00
now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second())
_, err = gs.PutObject(&Object{bucket, testKey},
&BufferCloser{bytes.NewBufferString("Delete Me")})
if err != nil {
t.Fatalf("Failed to put file to delete.")
}
err = gs.DeleteObject(&Object{bucket, testKey})
if err != nil {
t.Errorf("Failed to delete object: %v", err)
}
}
func TestEnumerateBucket(t *testing.T) {
gs, bucket := doConfig(t)
// Enumerate ALL the things!
objs, err := gs.EnumerateObjects(bucket, "", 0)
if err != nil {
t.Errorf("Enumeration failed: %v\n", err)
} else if len(objs) < 7 {
// Minimum number of blobs, equal to the number of files in testdata
t.Errorf("Expected at least 7 files, found %v", len(objs))
}
// Test a limited enum
objs, err = gs.EnumerateObjects(bucket, "", 5)
if err != nil {
t.Errorf("Enumeration failed: %v\n", err)
} else if len(objs) != 5 {
t.Errorf(
"Limited enum returned wrong number of blobs.\nExpected: %v\nFound: %v",
5, len(objs))
}
// Test fetching a limited set from a known start point
objs, err = gs.EnumerateObjects(bucket, "test-enum", 4)
if err != nil {
t.Errorf("Enumeration failed: %v\n", err)
} else {
for i := 0; i < 4; i += 1 {
if objs[i].Key != fmt.Sprintf("test-enum-%v", i+1) {
t.Errorf(
"Enum from start point returned wrong key:\nExpected: test-enum-%v\nFound: %v",
i+1, objs[i].Key)
}
}
}
}