diff --git a/go.mod b/go.mod index 083b3754..a35d18f8 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.21 require ( github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.1 github.com/Microsoft/go-winio v0.5.2 // indirect - github.com/aws/aws-sdk-go v1.53.15 github.com/bradfitz/gomemcache v0.0.0-20230905024940-24af94b03874 github.com/denisenkom/go-mssqldb v0.12.3 github.com/docker/docker v26.1.3+incompatible @@ -40,10 +39,33 @@ require ( k8s.io/client-go v0.29.1 ) +require ( + github.com/aws/aws-sdk-go-v2 v1.30.0 + github.com/aws/aws-sdk-go-v2/config v1.27.19 + github.com/aws/aws-sdk-go-v2/service/s3 v1.55.2 + github.com/aws/aws-sdk-go-v2/service/sns v1.30.1 + github.com/aws/aws-sdk-go-v2/service/sqs v1.33.1 +) + require ( github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.1 // indirect github.com/Azure/azure-sdk-for-go/sdk/internal v1.5.1 // indirect github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect + github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 // indirect + github.com/aws/aws-sdk-go-v2/credentials v1.17.19 // indirect + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.6 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.12 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.12 // indirect + github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect + github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.10 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.12 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.12 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.10 // indirect + github.com/aws/aws-sdk-go-v2/service/sso v1.20.12 // indirect + github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.6 // indirect + github.com/aws/aws-sdk-go-v2/service/sts v1.28.13 // indirect + github.com/aws/smithy-go v1.20.2 // indirect github.com/cenkalti/backoff/v3 v3.0.0 // indirect github.com/containerd/log v0.1.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect @@ -75,7 +97,6 @@ require ( github.com/hashicorp/hcl v1.0.0 // indirect github.com/imdario/mergo v0.3.12 // indirect github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf // indirect - github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.16.7 // indirect diff --git a/go.sum b/go.sum index e0111dfe..a8b3b03f 100644 --- a/go.sum +++ b/go.sum @@ -21,8 +21,46 @@ github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMz github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ= github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/aws/aws-sdk-go v1.53.15 h1:FtZmkg7xM8RfP2oY6p7xdKBYrRgkITk9yve2QV7N938= -github.com/aws/aws-sdk-go v1.53.15/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= +github.com/aws/aws-sdk-go-v2 v1.30.0 h1:6qAwtzlfcTtcL8NHtbDQAqgM5s6NDipQTkPxyH/6kAA= +github.com/aws/aws-sdk-go-v2 v1.30.0/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 h1:x6xsQXGSmW6frevwDA+vi/wqhp1ct18mVXYN08/93to= +github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2/go.mod h1:lPprDr1e6cJdyYeGXnRaJoP4Md+cDBvi2eOj00BlGmg= +github.com/aws/aws-sdk-go-v2/config v1.27.19 h1:+DBS8gJP6VsxYkZ6UEV0/VsRM2rYpbQCYsosW9RRmeQ= +github.com/aws/aws-sdk-go-v2/config v1.27.19/go.mod h1:KzZcioJWzy9oV+oS5CobYXlDtU9+eW7bPG1g7gizTW4= +github.com/aws/aws-sdk-go-v2/credentials v1.17.19 h1:R18G7nBBGLby51CFEqUBFF2IVl7LUdCtYj6iosUwh/0= +github.com/aws/aws-sdk-go-v2/credentials v1.17.19/go.mod h1:xr9kUMnaLTB866HItT6pg58JgiBP77fSQLBwIa//zk8= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.6 h1:vVOuhRyslJ6T/HteG71ZWCTas1q2w6f0NKsNbkXHs/A= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.6/go.mod h1:jimWaqLiT0sJGLh51dKCLLtExRYPtMU7MpxuCgtbkxg= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.12 h1:SJ04WXGTwnHlWIODtC5kJzKbeuHt+OUNOgKg7nfnUGw= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.12/go.mod h1:FkpvXhA92gb3GE9LD6Og0pHHycTxW7xGpnEh5E7Opwo= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.12 h1:hb5KgeYfObi5MHkSSZMEudnIvX30iB+E21evI4r6BnQ= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.12/go.mod h1:CroKe/eWJdyfy9Vx4rljP5wTUjNJfb+fPz1uMYUhEGM= +github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU= +github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.10 h1:KPPEosyvs2q6sGbRj/LIGMpqPStDZKtEy/CEbBl+tps= +github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.10/go.mod h1:6pZBDPNlCwrpj79TpGfjgaliXrC3lvoFGMCg7Rtc7p8= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 h1:Ji0DY1xUsUr3I8cHps0G+XM3WWU16lP6yG8qu1GAZAs= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2/go.mod h1:5CsjAbs3NlGQyZNFACh+zztPDI7fU6eW9QsxjfnuBKg= +github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.12 h1:77ORAasgQRiNRi1du4UVmttQg2Wf41WSe7TvpmpmDg0= +github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.12/go.mod h1:PsApornkaurUc1DIGUdiBzC19GfF1fy2ZH93O2JWigc= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.12 h1:kO2J7WMroF/OTHN9WTcUtMjPhJ7ZoNxx0dwv6UCXQgY= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.12/go.mod h1:mrNxrjYvXaSjZe5fkKaWgDnOQ6BExLn/7Ru9OpRsMPY= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.10 h1:1Hmy47QP13NjScoCMOr9kJo/hqKqf+tskyGpxVgNBxU= +github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.10/go.mod h1:8jZvhEt+MemeoHm9P4WFk/AVfIa9sCWL80OAKNDNTCM= +github.com/aws/aws-sdk-go-v2/service/s3 v1.55.2 h1:9UkFXpS7uU7ipUlj2sSkLtIo3Sa+LtbnObBJdx8yjd0= +github.com/aws/aws-sdk-go-v2/service/s3 v1.55.2/go.mod h1:Cijxa/K9vFQ9RPd16rq3cE+0Sg5hvmpEkTo+LThg43E= +github.com/aws/aws-sdk-go-v2/service/sns v1.30.1 h1:49R5Uh0Vi4Y21UHfLzmLmg7hwqQLyBmWqS0Vh+EpV2A= +github.com/aws/aws-sdk-go-v2/service/sns v1.30.1/go.mod h1:khPCTZaFImcuDtOLDqiveVdpQL53OXkK+/yoyao+kzk= +github.com/aws/aws-sdk-go-v2/service/sqs v1.33.1 h1:m/7a5OgAZQDWJlSbZLWg4BAlbXbY6j+dDDjPY8rZ7kA= +github.com/aws/aws-sdk-go-v2/service/sqs v1.33.1/go.mod h1:4kCM5tMCkys9PFbuGHP+LjpxlsA5oMRUs3QvnWo11BM= +github.com/aws/aws-sdk-go-v2/service/sso v1.20.12 h1:FsYii6U+2k8ynYBo+pywlCBY9HNAFRh+iICRHbn+Qyw= +github.com/aws/aws-sdk-go-v2/service/sso v1.20.12/go.mod h1:j9Rps+Lcs2A0tYypWsNBeJOjgsIYUf1Styppo9Es0Wo= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.6 h1:lEE+xEcq3lh9bk362tgErP1+n689q5ERdmTwmF1XT3M= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.6/go.mod h1:2tR0x1DCL5IgnVZ1NQNFDNg5/XL/kiQgWI5l7I/N5Js= +github.com/aws/aws-sdk-go-v2/service/sts v1.28.13 h1:TSzmuUeruVJ4XWYp3bYzKCXue70ECpJWmbP3UfEvhYY= +github.com/aws/aws-sdk-go-v2/service/sts v1.28.13/go.mod h1:FppRtFjBA9mSWTj2cIAWCP66+bbBPMuPpBfWRXC5Yi0= +github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q= +github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 h1:mXoPYz/Ul5HYEDvkta6I8/rnYM5gSdSV2tJ6XbZuEtY= github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k= @@ -175,10 +213,6 @@ github.com/influxdata/influxdb-client-go/v2 v2.13.0 h1:ioBbLmR5NMbAjP4UVA5r9b5xG github.com/influxdata/influxdb-client-go/v2 v2.13.0/go.mod h1:k+spCbt9hcvqvUiz0sr5D8LolXHqAAOfPw9v/RIRHl4= github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf h1:7JTmneyiNEwVBOHSjoMxiWAqB992atOeepeFYegn5RU= github.com/influxdata/line-protocol v0.0.0-20210922203350-b1ad95c89adf/go.mod h1:xaLFMmpvUxqXtVkUJfg9QmT88cDaCJ3ZKgdZ78oO8Qo= -github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= -github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= -github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= -github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= diff --git a/internal/gnomockd/localstack_test.go b/internal/gnomockd/localstack_test.go index 58f667e3..858e4e11 100644 --- a/internal/gnomockd/localstack_test.go +++ b/internal/gnomockd/localstack_test.go @@ -2,6 +2,7 @@ package gnomockd_test import ( "bytes" + "context" "encoding/json" "fmt" "io" @@ -11,10 +12,10 @@ import ( "strings" "testing" - "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" + "github.com/aws/aws-sdk-go-v2/aws" + + "github.com/aws/aws-sdk-go-v2/config" + "github.com/aws/aws-sdk-go-v2/service/s3" "github.com/orlangure/gnomock" "github.com/orlangure/gnomock/internal/gnomockd" "github.com/orlangure/gnomock/preset/localstack" @@ -47,26 +48,32 @@ func TestLocalstack(t *testing.T) { require.NoError(t, err) s3Endpoint := fmt.Sprintf("http://%s/", c.Address(localstack.APIPort)) - config := &aws.Config{ - Region: aws.String("us-east-1"), - Endpoint: aws.String(s3Endpoint), - S3ForcePathStyle: aws.Bool(true), - Credentials: credentials.NewStaticCredentials("a", "b", "c"), - } - sess, err := session.NewSession(config) + cfg, err := config.LoadDefaultConfig(context.TODO(), + config.WithRegion("us-east-1"), + config.WithCredentialsProvider(aws.CredentialsProviderFunc(func(_ context.Context) (aws.Credentials, error) { + return aws.Credentials{ + AccessKeyID: "a", + SecretAccessKey: "b", + SessionToken: "c", + }, nil + }, + ))) + require.NoError(t, err) - svc := s3.New(sess) + svc := s3.NewFromConfig(cfg, func(o *s3.Options) { + o.BaseEndpoint = &s3Endpoint + }) listInput := &s3.ListObjectsV2Input{Bucket: aws.String("some-bucket")} - files, err := svc.ListObjectsV2(listInput) + files, err := svc.ListObjectsV2(context.TODO(), listInput) require.NoError(t, err) require.Len(t, files.Contents, 100) require.False(t, *files.IsTruncated) for _, f := range files.Contents { - require.True(t, strings.HasPrefix(*f.Key, "file-")) + require.True(t, strings.HasPrefix(*f.Key, "/file-")) } bs, err = json.Marshal(c) diff --git a/preset/localstack/options_s3.go b/preset/localstack/options_s3.go index 99e6a81d..1d491ecc 100644 --- a/preset/localstack/options_s3.go +++ b/preset/localstack/options_s3.go @@ -1,15 +1,16 @@ package localstack import ( + "context" "fmt" "os" "path" "path/filepath" - "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" + "github.com/aws/aws-sdk-go-v2/config" + "github.com/aws/aws-sdk-go-v2/service/s3" + + "github.com/aws/aws-sdk-go-v2/aws" "github.com/orlangure/gnomock" ) @@ -36,19 +37,23 @@ func (p *P) initS3(c *gnomock.Container) error { } s3Endpoint := fmt.Sprintf("http://%s/", c.Address(APIPort)) - config := &aws.Config{ - Region: aws.String("us-east-1"), - Endpoint: aws.String(s3Endpoint), - S3ForcePathStyle: aws.Bool(true), - Credentials: credentials.NewStaticCredentials("a", "b", "c"), - } - - sess, err := session.NewSession(config) + cfg, err := config.LoadDefaultConfig(context.TODO(), + config.WithRegion("us-east-1"), + config.WithCredentialsProvider(aws.CredentialsProviderFunc(func(_ context.Context) (aws.Credentials, error) { + return aws.Credentials{ + AccessKeyID: "a", + SecretAccessKey: "b", + SessionToken: "c", + }, nil + }, + ))) if err != nil { - return fmt.Errorf("can't create s3 session: %w", err) + return fmt.Errorf("can't create s3 config: %w", err) } - svc := s3.New(sess) + svc := s3.NewFromConfig(cfg, func(o *s3.Options) { + o.BaseEndpoint = &s3Endpoint + }) buckets, err := p.createBuckets(svc) if err != nil { @@ -63,7 +68,7 @@ func (p *P) initS3(c *gnomock.Container) error { return nil } -func (p *P) createBuckets(svc *s3.S3) ([]string, error) { +func (p *P) createBuckets(svc *s3.Client) ([]string, error) { files, err := os.ReadDir(p.S3Path) if err != nil { return nil, fmt.Errorf("can't read s3 initial files: %w", err) @@ -90,17 +95,17 @@ func (p *P) createBuckets(svc *s3.S3) ([]string, error) { return buckets, nil } -func (p *P) createBucket(svc *s3.S3, bucket string) error { +func (p *P) createBucket(svc *s3.Client, bucket string) error { input := &s3.CreateBucketInput{Bucket: aws.String(bucket)} - if _, err := svc.CreateBucket(input); err != nil { + if _, err := svc.CreateBucket(context.TODO(), input); err != nil { return fmt.Errorf("can't create bucket '%s': %w", bucket, err) } return nil } -func (p *P) uploadFiles(svc *s3.S3, buckets []string) error { +func (p *P) uploadFiles(svc *s3.Client, buckets []string) error { for _, bucket := range buckets { bucket := bucket @@ -131,7 +136,7 @@ func (p *P) uploadFiles(svc *s3.S3, buckets []string) error { return nil } -func (p *P) uploadFile(svc *s3.S3, bucket, file string) (err error) { +func (p *P) uploadFile(svc *s3.Client, bucket, file string) (err error) { inputFile, err := os.Open(file) //nolint:gosec if err != nil { return fmt.Errorf("can't open file '%s': %w", file, err) @@ -153,7 +158,7 @@ func (p *P) uploadFile(svc *s3.S3, bucket, file string) (err error) { Body: inputFile, } - _, err = svc.PutObject(input) + _, err = svc.PutObject(context.TODO(), input) if err != nil { return fmt.Errorf("can't upload file '%s' to bucket '%s': %w", file, bucket, err) } diff --git a/preset/localstack/preset_test.go b/preset/localstack/preset_test.go index 75712a5e..530ab492 100644 --- a/preset/localstack/preset_test.go +++ b/preset/localstack/preset_test.go @@ -2,17 +2,18 @@ package localstack_test import ( "bytes" + "context" "encoding/json" "fmt" "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" - "github.com/aws/aws-sdk-go/service/sns" - "github.com/aws/aws-sdk-go/service/sqs" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/config" + "github.com/aws/aws-sdk-go-v2/service/s3" + "github.com/aws/aws-sdk-go-v2/service/sns" + "github.com/aws/aws-sdk-go-v2/service/sqs" + "github.com/aws/aws-sdk-go-v2/service/sqs/types" "github.com/orlangure/gnomock" "github.com/orlangure/gnomock/preset/localstack" "github.com/stretchr/testify/require" @@ -45,36 +46,42 @@ func testS3(version string) func(*testing.T) { require.NoError(t, err) s3Endpoint := fmt.Sprintf("http://%s/", c.Address(localstack.APIPort)) - config := &aws.Config{ - Region: aws.String("us-east-1"), - Endpoint: aws.String(s3Endpoint), - S3ForcePathStyle: aws.Bool(true), - Credentials: credentials.NewStaticCredentials("a", "b", "c"), - } - sess, err := session.NewSession(config) + cfg, err := config.LoadDefaultConfig(context.TODO(), + config.WithRegion("us-east-1"), + config.WithCredentialsProvider(aws.CredentialsProviderFunc(func(_ context.Context) (aws.Credentials, error) { + return aws.Credentials{ + AccessKeyID: "a", + SecretAccessKey: "b", + SessionToken: "c", + }, nil + }, + ))) + require.NoError(t, err) - svc := s3.New(sess) + svc := s3.NewFromConfig(cfg, func(o *s3.Options) { + o.BaseEndpoint = &s3Endpoint + }) - _, err = svc.CreateBucket(&s3.CreateBucketInput{ + _, err = svc.CreateBucket(context.TODO(), &s3.CreateBucketInput{ Bucket: aws.String("foo"), }) require.NoError(t, err) - out, err := svc.ListObjectsV2(&s3.ListObjectsV2Input{ + out, err := svc.ListObjectsV2(context.TODO(), &s3.ListObjectsV2Input{ Bucket: aws.String("foo"), }) require.NoError(t, err) require.Empty(t, out.Contents) - _, err = svc.PutObject(&s3.PutObjectInput{ + _, err = svc.PutObject(context.TODO(), &s3.PutObjectInput{ Body: bytes.NewReader([]byte("this is a file")), Key: aws.String("file"), Bucket: aws.String("foo"), }) require.NoError(t, err) - out, err = svc.ListObjectsV2(&s3.ListObjectsV2Input{ + out, err = svc.ListObjectsV2(context.TODO(), &s3.ListObjectsV2Input{ Bucket: aws.String("foo"), }) require.NoError(t, err) @@ -110,62 +117,75 @@ func TestPreset_sqs_sns(t *testing.T) { endpoint := fmt.Sprintf("http://%s", c.Address(localstack.APIPort)) - sess, err := session.NewSession(&aws.Config{ - Region: aws.String("us-east-1"), - Endpoint: aws.String(endpoint), - Credentials: credentials.NewStaticCredentials("a", "b", "c"), + sqsService := sqs.New(sqs.Options{ + BaseEndpoint: &endpoint, + Credentials: aws.CredentialsProviderFunc(func(_ context.Context) (aws.Credentials, error) { + return aws.Credentials{ + AccessKeyID: "a", + SecretAccessKey: "b", + SessionToken: "c", + }, nil + }), + Region: "us-east-1", + }) + snsService := sns.New(sns.Options{ + BaseEndpoint: &endpoint, + Credentials: aws.CredentialsProviderFunc(func(_ context.Context) (aws.Credentials, error) { + return aws.Credentials{ + AccessKeyID: "a", + SecretAccessKey: "b", + SessionToken: "c", + }, nil + }), + Region: "us-east-1", }) - require.NoError(t, err) - - sqsService := sqs.New(sess) - snsService := sns.New(sess) - _, err = sqsService.CreateQueue(&sqs.CreateQueueInput{ + _, err = sqsService.CreateQueue(context.TODO(), &sqs.CreateQueueInput{ QueueName: aws.String("my_queue"), }) require.NoError(t, err) - attrs, err := sqsService.GetQueueAttributes(&sqs.GetQueueAttributesInput{ + attrs, err := sqsService.GetQueueAttributes(context.TODO(), &sqs.GetQueueAttributesInput{ QueueUrl: aws.String("my_queue"), - AttributeNames: []*string{aws.String("QueueArn")}, + AttributeNames: []types.QueueAttributeName{types.QueueAttributeNameQueueArn}, }) require.NoError(t, err) require.Len(t, attrs.Attributes, 1) - _, err = snsService.CreateTopic(&sns.CreateTopicInput{ + _, err = snsService.CreateTopic(context.TODO(), &sns.CreateTopicInput{ Name: aws.String("my_topic"), }) require.NoError(t, err) - queues, err := sqsService.ListQueues(&sqs.ListQueuesInput{}) + queues, err := sqsService.ListQueues(context.TODO(), &sqs.ListQueuesInput{}) require.NoError(t, err) require.Len(t, queues.QueueUrls, 1) queueURL := queues.QueueUrls[0] queueARN := attrs.Attributes["QueueArn"] - topics, err := snsService.ListTopics(&sns.ListTopicsInput{}) + topics, err := snsService.ListTopics(context.TODO(), &sns.ListTopicsInput{}) require.NoError(t, err) require.Equal(t, 1, len(topics.Topics)) topic := topics.Topics[0] - _, err = snsService.Subscribe(&sns.SubscribeInput{ + _, err = snsService.Subscribe(context.TODO(), &sns.SubscribeInput{ Protocol: aws.String("sqs"), - Endpoint: queueARN, + Endpoint: &queueARN, TopicArn: topic.TopicArn, }) require.NoError(t, err) - _, err = snsService.Publish(&sns.PublishInput{ + _, err = snsService.Publish(context.TODO(), &sns.PublishInput{ TopicArn: topic.TopicArn, Message: aws.String("foobar"), }) require.NoError(t, err) - messages, err := sqsService.ReceiveMessage(&sqs.ReceiveMessageInput{ - QueueUrl: queueURL, - WaitTimeSeconds: aws.Int64(1), + messages, err := sqsService.ReceiveMessage(context.TODO(), &sqs.ReceiveMessageInput{ + QueueUrl: &queueURL, + WaitTimeSeconds: *aws.Int32(1), }) require.NoError(t, err) require.Equal(t, 1, len(messages.Messages)) diff --git a/preset/localstack/s3_test.go b/preset/localstack/s3_test.go index af9b027e..e7f887af 100644 --- a/preset/localstack/s3_test.go +++ b/preset/localstack/s3_test.go @@ -1,14 +1,16 @@ package localstack_test import ( + "context" "fmt" "strings" "testing" - "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" + "github.com/aws/aws-sdk-go-v2/config" + "github.com/aws/aws-sdk-go-v2/service/s3" + + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/orlangure/gnomock" "github.com/orlangure/gnomock/preset/localstack" "github.com/stretchr/testify/require" @@ -28,58 +30,65 @@ func TestWithS3Files(t *testing.T) { require.NoError(t, err) s3Endpoint := fmt.Sprintf("http://%s/", c.Address(localstack.APIPort)) - config := &aws.Config{ - Region: aws.String("us-east-1"), - Endpoint: aws.String(s3Endpoint), - S3ForcePathStyle: aws.Bool(true), - Credentials: credentials.NewStaticCredentials("a", "b", "c"), - } - sess, err := session.NewSession(config) + cfg, err := config.LoadDefaultConfig(context.TODO(), + config.WithRegion("us-east-1"), + config.WithCredentialsProvider(aws.CredentialsProviderFunc(func(_ context.Context) (aws.Credentials, error) { + return aws.Credentials{ + AccessKeyID: "a", + SecretAccessKey: "b", + SessionToken: "c", + }, nil + }, + ))) + require.NoError(t, err) - svc := s3.New(sess) + svc := s3.NewFromConfig(cfg, func(o *s3.Options) { + o.BaseEndpoint = &s3Endpoint + }) // my-bucket is automatically created, and now includes 100 files listInput := &s3.ListObjectsV2Input{ Bucket: aws.String("my-bucket"), - MaxKeys: aws.Int64(40), + MaxKeys: aws.Int32(40), } - files, err := svc.ListObjectsV2(listInput) + + files, err := svc.ListObjectsV2(context.TODO(), listInput) require.NoError(t, err) require.Len(t, files.Contents, 40) require.True(t, *files.IsTruncated) for _, f := range files.Contents { - require.True(t, strings.HasPrefix(*f.Key, "dir/f-")) + require.True(t, strings.HasPrefix(*f.Key, "/dir/f-")) } listInput = &s3.ListObjectsV2Input{ Bucket: aws.String("my-bucket"), ContinuationToken: files.NextContinuationToken, - MaxKeys: aws.Int64(50), + MaxKeys: aws.Int32(50), } - files, err = svc.ListObjectsV2(listInput) + files, err = svc.ListObjectsV2(context.TODO(), listInput) require.NoError(t, err) require.Len(t, files.Contents, 50) require.True(t, *files.IsTruncated) for _, f := range files.Contents { - require.True(t, strings.HasPrefix(*f.Key, "dir/f-")) + require.True(t, strings.HasPrefix(*f.Key, "/dir/f-")) } // list last batch of files, only 10 left listInput = &s3.ListObjectsV2Input{ Bucket: aws.String("my-bucket"), ContinuationToken: files.NextContinuationToken, - MaxKeys: aws.Int64(100), + MaxKeys: aws.Int32(100), } - files, err = svc.ListObjectsV2(listInput) + files, err = svc.ListObjectsV2(context.TODO(), listInput) require.NoError(t, err) require.Len(t, files.Contents, 10) require.False(t, *files.IsTruncated) for _, f := range files.Contents { - require.True(t, strings.HasPrefix(*f.Key, "dir/f-")) + require.True(t, strings.HasPrefix(*f.Key, "/dir/f-")) } }