diff options
| author | Marin Ivanov <[email protected]> | 2024-04-05 04:28:13 +0300 |
|---|---|---|
| committer | Marin Ivanov <[email protected]> | 2024-04-05 04:28:13 +0300 |
| commit | 1705d77f21ee186aa65b5e40d3febfefe4e1067c (patch) | |
| tree | 90ebcc29b0fd1696f70c977954c0b7396dc0c42c /util_test.go | |
| parent | d3e042630ea96d7d2d7ca43ddd4334455c0c7004 (diff) | |
improve tests
Diffstat (limited to 'util_test.go')
| -rw-r--r-- | util_test.go | 47 |
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("") + } +} |
