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("") } }