summaryrefslogtreecommitdiff
path: root/util_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'util_test.go')
-rw-r--r--util_test.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/util_test.go b/util_test.go
new file mode 100644
index 0000000..ff700be
--- /dev/null
+++ b/util_test.go
@@ -0,0 +1,47 @@
+package s3
+
+import (
+ "context"
+ "fmt"
+ "time"
+
+ "github.com/minio/minio-go/v7"
+ "github.com/minio/minio-go/v7/pkg/credentials"
+ "github.com/spf13/afero"
+)
+
+func newTestAfs() (*afero.Afero, func()) {
+ accessKeyID := "testuser"
+ secretAccessKey := "testsecret"
+ endpoint := "127.0.0.1:9000"
+ useSSL := false
+ bucket := "test-bucket"
+
+ client, err := minio.New(endpoint, &minio.Options{
+ Creds: credentials.NewStaticV4(accessKeyID, secretAccessKey, ""),
+ Secure: useSSL,
+ })
+ if err != nil {
+ panic("unable connect")
+ }
+ ctx, cancel := context.WithTimeout(context.Background(), time.Second)
+ defer cancel()
+
+ if exists, err := client.BucketExists(ctx, bucket); err != nil {
+ panic("unable connect")
+ } else if !exists {
+ if err := client.MakeBucket(ctx, bucket, minio.MakeBucketOptions{}); err != nil {
+ panic("failed to seup a bucket")
+ }
+ }
+
+ url := fmt.Sprintf("http://%s:%s@%s/%s", accessKeyID, secretAccessKey, endpoint, bucket)
+ fs, err := NewFsFromURL(url)
+ if err != nil {
+ panic("unexpected error")
+ }
+ afs := &afero.Afero{Fs: fs}
+ return afs, func() {
+ afs.RemoveAll("")
+ }
+}