Skip to content

Commit 301ecad

Browse files
committed
minor improvements; linter improvements;
1 parent 24fb9b2 commit 301ecad

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

framework/components/s3provider/minio.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ package s3provider
33
import (
44
"context"
55
"fmt"
6+
"math/rand"
7+
"net"
8+
"os"
9+
"strconv"
10+
611
"github.com/docker/docker/api/types/container"
712
"github.com/docker/go-connections/nat"
813
"github.com/minio/minio-go/v7"
914
"github.com/minio/minio-go/v7/pkg/credentials"
1015
"github.com/smartcontractkit/chainlink-testing-framework/framework"
1116
tc "github.com/testcontainers/testcontainers-go"
1217
tcwait "github.com/testcontainers/testcontainers-go/wait"
13-
"math/rand"
14-
"os"
15-
"strconv"
1618
)
1719

1820
const (
@@ -22,6 +24,9 @@ const (
2224
DefaultRegion = "us-east-1"
2325
DefaultPort = 9000
2426
DefaultConsolePort = 9001
27+
28+
accessKeyLength = 20
29+
secretKeyLength = 40
2530
)
2631

2732
type Minio struct {
@@ -48,7 +53,7 @@ func (m Minio) GetBucket() string {
4853
}
4954

5055
func (m Minio) GetConsoleURL() string {
51-
return fmt.Sprintf("http://%s:%d", m.host, m.consolePort)
56+
return fmt.Sprintf("http://%s", net.JoinHostPort(m.host, strconv.Itoa(m.consolePort)))
5257
}
5358

5459
func (m Minio) GetEndpoint() string {
@@ -71,8 +76,8 @@ func (mf MinioFactory) New(options ...Option) (Provider, error) {
7176
m := &Minio{
7277
port: DefaultPort,
7378
consolePort: DefaultConsolePort,
74-
accessKey: randomStr(20),
75-
secretKey: randomStr(40),
79+
accessKey: randomStr(accessKeyLength),
80+
secretKey: randomStr(secretKeyLength),
7681
bucket: DefaultBucket,
7782
region: DefaultRegion,
7883
keep: false,
@@ -82,11 +87,16 @@ func (mf MinioFactory) New(options ...Option) (Provider, error) {
8287
opt(m)
8388
}
8489

85-
var tcRyukDisabled string
90+
var (
91+
tcRyukDisabled string
92+
err error
93+
)
94+
8695
if m.keep {
8796
// store original env var to value
8897
tcRyukDisabled = os.Getenv("TESTCONTAINERS_RYUK_DISABLED")
89-
err := os.Setenv("TESTCONTAINERS_RYUK_DISABLED", "true")
98+
err = os.Setenv("TESTCONTAINERS_RYUK_DISABLED", "true")
99+
90100
if err != nil {
91101
return nil, err
92102
}
@@ -166,11 +176,10 @@ func (mf MinioFactory) New(options ...Option) (Provider, error) {
166176
return nil, err
167177
}
168178

169-
host, err := framework.GetHost(c)
179+
m.host, err = framework.GetHost(c)
170180
if err != nil {
171181
return nil, err
172182
}
173-
m.host = host
174183

175184
// Initialize minio client object.
176185
minioClient, err := minio.New(m.GetEndpoint(), &minio.Options{
@@ -179,13 +188,15 @@ func (mf MinioFactory) New(options ...Option) (Provider, error) {
179188
})
180189
if err != nil {
181190
framework.L.Warn().Str("error", err.Error()).Msg("failed to create minio client")
191+
182192
return nil, err
183193
}
184194

185195
// Initialize default bucket
186196
err = minioClient.MakeBucket(ctx, m.GetBucket(), minio.MakeBucketOptions{Region: m.GetRegion()})
187197
if err != nil {
188198
framework.L.Warn().Str("error", err.Error()).Msg("failed to create minio bucket")
199+
189200
return nil, err
190201
}
191202

@@ -237,5 +248,6 @@ func randomStr(n int) string {
237248
for i := range b {
238249
b[i] = letterBytes[rand.Int63()%int64(len(letterBytes))]
239250
}
251+
240252
return string(b)
241253
}

framework/components/s3provider/minio_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package s3provider
22

33
import (
44
"context"
5+
"testing"
6+
57
"github.com/hashicorp/consul/sdk/freeport"
68
"github.com/minio/minio-go/v7"
79
"github.com/minio/minio-go/v7/pkg/credentials"
810
"github.com/stretchr/testify/require"
9-
"testing"
1011
)
1112

1213
func TestNewMinioFactory(t *testing.T) {

0 commit comments

Comments
 (0)