mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-19 08:46:38 +00:00
Replace discontinued LocalStack image with MinIO in S3 test (#5680)
This commit is contained in:
2
go.mod
2
go.mod
@@ -33,6 +33,7 @@ require (
|
|||||||
github.com/awnumar/memguard v0.23.0
|
github.com/awnumar/memguard v0.23.0
|
||||||
github.com/aws/aws-sdk-go-v2 v1.36.3
|
github.com/aws/aws-sdk-go-v2 v1.36.3
|
||||||
github.com/aws/aws-sdk-go-v2/config v1.29.14
|
github.com/aws/aws-sdk-go-v2/config v1.29.14
|
||||||
|
github.com/aws/aws-sdk-go-v2/credentials v1.17.67
|
||||||
github.com/aws/aws-sdk-go-v2/service/s3 v1.79.2
|
github.com/aws/aws-sdk-go-v2/service/s3 v1.79.2
|
||||||
github.com/c-robinson/iplib v1.0.3
|
github.com/c-robinson/iplib v1.0.3
|
||||||
github.com/caddyserver/certmagic v0.21.3
|
github.com/caddyserver/certmagic v0.21.3
|
||||||
@@ -143,7 +144,6 @@ require (
|
|||||||
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
|
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
|
||||||
github.com/awnumar/memcall v0.4.0 // indirect
|
github.com/awnumar/memcall v0.4.0 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.10 // indirect
|
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.10 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/credentials v1.17.67 // indirect
|
|
||||||
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.30 // indirect
|
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.30 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34 // indirect
|
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34 // indirect
|
||||||
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.34 // indirect
|
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.34 // indirect
|
||||||
|
|||||||
@@ -5,13 +5,12 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go-v2/config"
|
"github.com/aws/aws-sdk-go-v2/config"
|
||||||
|
"github.com/aws/aws-sdk-go-v2/credentials"
|
||||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/testcontainers/testcontainers-go"
|
"github.com/testcontainers/testcontainers-go"
|
||||||
"github.com/testcontainers/testcontainers-go/wait"
|
"github.com/testcontainers/testcontainers-go/wait"
|
||||||
@@ -20,45 +19,55 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Test_S3HandlerGetUploadURL(t *testing.T) {
|
func Test_S3HandlerGetUploadURL(t *testing.T) {
|
||||||
if runtime.GOOS != "linux" && os.Getenv("CI") == "true" {
|
if runtime.GOOS != "linux" {
|
||||||
t.Skip("Skipping test on non-Linux and CI environment due to docker dependency")
|
t.Skip("Skipping test on non-Linux due to docker dependency")
|
||||||
}
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
t.Skip("Skipping test on Windows due to potential docker dependency")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
awsEndpoint := "http://127.0.0.1:4566"
|
|
||||||
awsRegion := "us-east-1"
|
awsRegion := "us-east-1"
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
containerRequest := testcontainers.ContainerRequest{
|
|
||||||
Image: "localstack/localstack:s3-latest",
|
|
||||||
ExposedPorts: []string{"4566:4566/tcp"},
|
|
||||||
WaitingFor: wait.ForLog("Ready"),
|
|
||||||
}
|
|
||||||
|
|
||||||
c, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
|
c, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
|
||||||
ContainerRequest: containerRequest,
|
ContainerRequest: testcontainers.ContainerRequest{
|
||||||
Started: true,
|
Image: "minio/minio:RELEASE.2025-04-22T22-12-26Z",
|
||||||
|
ExposedPorts: []string{"9000/tcp"},
|
||||||
|
Env: map[string]string{
|
||||||
|
"MINIO_ROOT_USER": "minioadmin",
|
||||||
|
"MINIO_ROOT_PASSWORD": "minioadmin",
|
||||||
|
},
|
||||||
|
Cmd: []string{"server", "/data"},
|
||||||
|
WaitingFor: wait.ForHTTP("/minio/health/ready").WithPort("9000"),
|
||||||
|
},
|
||||||
|
Started: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Error(err)
|
t.Cleanup(func() {
|
||||||
}
|
|
||||||
defer func(c testcontainers.Container, ctx context.Context) {
|
|
||||||
if err := c.Terminate(ctx); err != nil {
|
if err := c.Terminate(ctx); err != nil {
|
||||||
t.Log(err)
|
t.Log(err)
|
||||||
}
|
}
|
||||||
}(c, ctx)
|
})
|
||||||
|
|
||||||
|
mappedPort, err := c.MappedPort(ctx, "9000")
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
hostIP, err := c.Host(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
awsEndpoint := "http://" + hostIP + ":" + mappedPort.Port()
|
||||||
|
|
||||||
t.Setenv("AWS_REGION", awsRegion)
|
t.Setenv("AWS_REGION", awsRegion)
|
||||||
t.Setenv("AWS_ENDPOINT_URL", awsEndpoint)
|
t.Setenv("AWS_ENDPOINT_URL", awsEndpoint)
|
||||||
t.Setenv("AWS_ACCESS_KEY_ID", "test")
|
t.Setenv("AWS_ACCESS_KEY_ID", "minioadmin")
|
||||||
t.Setenv("AWS_SECRET_ACCESS_KEY", "test")
|
t.Setenv("AWS_SECRET_ACCESS_KEY", "minioadmin")
|
||||||
|
t.Setenv("AWS_CONFIG_FILE", "")
|
||||||
|
t.Setenv("AWS_SHARED_CREDENTIALS_FILE", "")
|
||||||
|
t.Setenv("AWS_PROFILE", "")
|
||||||
|
|
||||||
cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion(awsRegion), config.WithBaseEndpoint(awsEndpoint))
|
cfg, err := config.LoadDefaultConfig(ctx,
|
||||||
if err != nil {
|
config.WithRegion(awsRegion),
|
||||||
t.Error(err)
|
config.WithBaseEndpoint(awsEndpoint),
|
||||||
}
|
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider("minioadmin", "minioadmin", "")),
|
||||||
|
)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
client := s3.NewFromConfig(cfg, func(o *s3.Options) {
|
client := s3.NewFromConfig(cfg, func(o *s3.Options) {
|
||||||
o.UsePathStyle = true
|
o.UsePathStyle = true
|
||||||
@@ -66,19 +75,16 @@ func Test_S3HandlerGetUploadURL(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
bucketName := "test"
|
bucketName := "test"
|
||||||
if _, err := client.CreateBucket(ctx, &s3.CreateBucketInput{
|
_, err = client.CreateBucket(ctx, &s3.CreateBucketInput{
|
||||||
Bucket: &bucketName,
|
Bucket: &bucketName,
|
||||||
}); err != nil {
|
})
|
||||||
t.Error(err)
|
require.NoError(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
list, err := client.ListBuckets(ctx, &s3.ListBucketsInput{})
|
list, err := client.ListBuckets(ctx, &s3.ListBucketsInput{})
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.Equal(t, len(list.Buckets), 1)
|
require.Len(t, list.Buckets, 1)
|
||||||
assert.Equal(t, *list.Buckets[0].Name, bucketName)
|
require.Equal(t, bucketName, *list.Buckets[0].Name)
|
||||||
|
|
||||||
t.Setenv(bucketVar, bucketName)
|
t.Setenv(bucketVar, bucketName)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user