diff options
| author | Marin Ivanov <[email protected]> | 2022-08-14 20:44:07 +0300 |
|---|---|---|
| committer | Marin Ivanov <[email protected]> | 2022-08-14 20:44:07 +0300 |
| commit | c5018208a56d0a3b52d0d7810bfcb08da629b94a (patch) | |
| tree | ed88204b24913ce99d9d69d8b3c0e2555757bc86 | |
| parent | 46ff67ebdcdcc632958a8598ce694b3d3f9056e8 (diff) | |
Rudimentary test
| -rw-r--r-- | fs.go | 4 | ||||
| -rw-r--r-- | fs_test.go | 16 | ||||
| -rw-r--r-- | go.mod | 5 | ||||
| -rw-r--r-- | go.sum | 2 | ||||
| -rw-r--r-- | testing.go | 15 |
5 files changed, 41 insertions, 1 deletions
@@ -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) +} @@ -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 @@ -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 +} |
