Skip to content

Commit

Permalink
Merge pull request #45 from 88labs/fix/awssqs-local-mock-endpoint
Browse files Browse the repository at this point in the history
fix awssqs local mock endpoint option
  • Loading branch information
tomtwinkle authored Oct 12, 2022
2 parents d8e4746 + 2c1eed8 commit 28ed806
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
11 changes: 8 additions & 3 deletions aws/awssqs/awssqs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ const (
)

func Cleanup() {
ctx := ctxawslocal.WithContext(context.Background())
ctx := ctxawslocal.WithContext(
context.Background(),
ctxawslocal.WithAccessKey("DUMMYACCESSKEYEXAMPLE"),
ctxawslocal.WithSecretAccessKey("DUMMYSECRETKEYEXAMPLE"),
ctxawslocal.WithSQSEndpoint("http://127.0.0.1:4566"),
)
res, err := awssqs.ReceiveMessage(ctx, TestRegion, TestQueue,
sqsreceive.WithWaitTimeSeconds(0),
sqsreceive.WithMaxNumberOfMessages(10))
Expand All @@ -47,7 +52,7 @@ func TestSentMessage(t *testing.T) {
context.Background(),
ctxawslocal.WithAccessKey("DUMMYACCESSKEYEXAMPLE"),
ctxawslocal.WithSecretAccessKey("DUMMYSECRETKEYEXAMPLE"),
ctxawslocal.WithS3Endpoint("http://127.0.0.1:4566"),
ctxawslocal.WithSQSEndpoint("http://127.0.0.1:4566"),
)

t.Cleanup(Cleanup)
Expand Down Expand Up @@ -92,7 +97,7 @@ func TestRetrieveAndDeleteMessage(t *testing.T) {
context.Background(),
ctxawslocal.WithAccessKey("DUMMYACCESSKEYEXAMPLE"),
ctxawslocal.WithSecretAccessKey("DUMMYSECRETKEYEXAMPLE"),
ctxawslocal.WithS3Endpoint("http://127.0.0.1:4566"),
ctxawslocal.WithSQSEndpoint("http://127.0.0.1:4566"),
)

t.Cleanup(Cleanup)
Expand Down
2 changes: 1 addition & 1 deletion aws/awssqs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type LocalProfile struct {
func getLocalEndpoint(ctx context.Context) (*LocalProfile, bool) {
if c, ok := ctxawslocal.GetConf(ctx); ok {
p := new(LocalProfile)
p.Endpoint = c.S3Endpoint
p.Endpoint = c.SQSEndpoint
p.AccessKey = c.AccessKey
p.SecretAccessKey = c.SecretAccessKey
return p, true
Expand Down
5 changes: 4 additions & 1 deletion aws/ctxawslocal/ctxawslocal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,24 @@ func TestGetConf(t *testing.T) {
assert.Equal(t, &ctxawslocal.ConfMock{
AccessKey: "test", //localstack default AccessKey
SecretAccessKey: "test", // localstack default SecretAccessKey
S3Endpoint: "http://127.0.0.1:4566", // localhost
S3Endpoint: "http://127.0.0.1:4566", // localstack default endpoint
SQSEndpoint: "http://127.0.0.1:4566", // localstack default endpoint
}, c)
})
t.Run("set config", func(t *testing.T) {
ctx := ctxawslocal.WithContext(context.Background(),
ctxawslocal.WithAccessKey("DUMMYACCESSKEYEXAMPLE"),
ctxawslocal.WithSecretAccessKey("DUMMYACCESSKEYEXAMPLE"),
ctxawslocal.WithS3Endpoint("http://localhost:14572"),
ctxawslocal.WithSQSEndpoint("http://localhost:24572"),
)
c, ok := ctxawslocal.GetConf(ctx)
assert.True(t, ok)
assert.Equal(t, &ctxawslocal.ConfMock{
AccessKey: "DUMMYACCESSKEYEXAMPLE",
SecretAccessKey: "DUMMYACCESSKEYEXAMPLE",
S3Endpoint: "http://localhost:14572",
SQSEndpoint: "http://localhost:24572",
}, c)
})
}
12 changes: 12 additions & 0 deletions aws/ctxawslocal/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type ConfMock struct {
AccessKey string
SecretAccessKey string
S3Endpoint string
SQSEndpoint string
}

// nolint:revive
Expand All @@ -17,6 +18,7 @@ func getConf(opts ...OptionMock) ConfMock {
AccessKey: "test", // localstack default AccessKey
SecretAccessKey: "test", // localstack default SecretAccessKey
S3Endpoint: "http://127.0.0.1:4566", // localstack default endpoint
SQSEndpoint: "http://127.0.0.1:4566", // localstack default endpoint
}
for _, opt := range opts {
opt.Apply(&c)
Expand Down Expand Up @@ -53,3 +55,13 @@ func (o OptionS3Endpoint) Apply(c *ConfMock) {
func WithS3Endpoint(endpoint string) OptionS3Endpoint {
return OptionS3Endpoint(endpoint)
}

type OptionSQSEndpoint string

func (o OptionSQSEndpoint) Apply(c *ConfMock) {
c.SQSEndpoint = string(o)
}

func WithSQSEndpoint(endpoint string) OptionSQSEndpoint {
return OptionSQSEndpoint(endpoint)
}

0 comments on commit 28ed806

Please sign in to comment.