Skip to content

Commit

Permalink
Fixed S3 test integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Janos Bonic committed Jun 5, 2022
1 parent 2bdaf03 commit 4369e15
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions internal/test/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package test

import (
"fmt"
"net"
"testing"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)

// s3Lock is used to start a maximum of 5 Minio instances for testing.
Expand Down Expand Up @@ -33,7 +37,7 @@ func S3(t *testing.T) S3Helper {
cnt: containerFromPull(
t,
"docker.io/minio/minio",
[]string{"server", "/testdata"},
[]string{"server", "/data", "--console-address", ":9001"},
env,
map[string]string{
"9000/tcp": "",
Expand Down Expand Up @@ -99,14 +103,31 @@ func (m *minio) wait() {
if tries > 30 {
m.t.Fatalf("Minio failed to come up in %d seconds.", sleepTime*30)
}
sock, err := net.Dial("tcp", fmt.Sprintf("127.0.0.1:%d", m.cnt.port("9000/tcp")))
time.Sleep(time.Duration(sleepTime) * time.Second)
if err != nil {
tries++
awsConfig := &aws.Config{
Credentials: credentials.NewCredentials(
&credentials.StaticProvider{
Value: credentials.Value{
AccessKeyID: m.accessKey,
SecretAccessKey: m.secretKey,
},
},
),
Endpoint: aws.String(m.URL()),
Region: aws.String(m.Region()),
S3ForcePathStyle: aws.Bool(m.PathStyle()),
}
sess, err := session.NewSession(awsConfig)
if err == nil {
s3Connection := s3.New(sess)
_, err := s3Connection.ListBuckets(&s3.ListBucketsInput{})
if err == nil {
return
}
m.t.Logf("S3 is not up yet, failed to list buckets (%v)", err)
} else {
_ = sock.Close()

return
m.t.Logf("S3 is not up yet, failed to create S3 session (%v)", err)
}
time.Sleep(time.Duration(sleepTime) * time.Second)
tries++
}
}

0 comments on commit 4369e15

Please sign in to comment.