summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fs.go4
-rw-r--r--fs_test.go16
-rw-r--r--go.mod5
-rw-r--r--go.sum2
-rw-r--r--testing.go15
5 files changed, 41 insertions, 1 deletions
diff --git a/fs.go b/fs.go
index 18ebb5a..1baa723 100644
--- a/fs.go
+++ b/fs.go
@@ -116,3 +116,7 @@ func (fs *Fs) Chown(name string, uid, gid int) error {
func (fs *Fs) Chtimes(name string, atime time.Time, mtime time.Time) error {
panic("not implemented")
}
+
+func (fs *Fs) contextWithTimeout() (context.Context, context.CancelFunc) {
+ return context.WithTimeout(context.Background(), fs.Timeout)
+}
diff --git a/fs_test.go b/fs_test.go
new file mode 100644
index 0000000..1677415
--- /dev/null
+++ b/fs_test.go
@@ -0,0 +1,16 @@
+package s3
+
+import (
+ "testing"
+
+ "github.com/matryer/is"
+)
+
+func TestFsInit(t *testing.T) {
+ is := is.New(t)
+ fs, err := NewFs("127.0.0.1:9000", "test-bucket", "testuser", "testsecret", false)
+ is.NoErr(err)
+ buckets, err := fs.listBuckets()
+ is.NoErr(err)
+ is.Equal(len(buckets), 1)
+}
diff --git a/go.mod b/go.mod
index b5dfbd8..d26aa76 100644
--- a/go.mod
+++ b/go.mod
@@ -2,7 +2,10 @@ module go.metala.org/afero/s3
go 1.17
-require github.com/minio/minio-go/v7 v7.0.34
+require (
+ github.com/matryer/is v1.4.0
+ github.com/minio/minio-go/v7 v7.0.34
+)
require (
github.com/dustin/go-humanize v1.0.0 // indirect
diff --git a/go.sum b/go.sum
index 702df11..e06cbea 100644
--- a/go.sum
+++ b/go.sum
@@ -14,6 +14,8 @@ github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.1.0 h1:eyi1Ad2aNJMW95zcSbmGg7Cg6cq3ADwLpMAP96d8rF0=
github.com/klauspost/cpuid/v2 v2.1.0/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
+github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE=
+github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
github.com/minio/minio-go/v7 v7.0.34 h1:JMfS5fudx1mN6V2MMNyCJ7UMrjEzZzIvMgfkWc1Vnjk=
diff --git a/testing.go b/testing.go
new file mode 100644
index 0000000..8286abc
--- /dev/null
+++ b/testing.go
@@ -0,0 +1,15 @@
+package s3
+
+func (fs *Fs) listBuckets() ([]string, error) {
+ ctx, cancel := fs.contextWithTimeout()
+ defer cancel()
+ bucketInfos, err := fs.client.ListBuckets(ctx)
+ if err != nil {
+ return nil, err
+ }
+ buckets := make([]string, 0, len(bucketInfos))
+ for _, bi := range bucketInfos {
+ buckets = append(buckets, bi.Name)
+ }
+ return buckets, nil
+}