Skip to content

Commit

Permalink
📋 Remove deprecated StartWithContext from examples
Browse files Browse the repository at this point in the history
  • Loading branch information
elgohr committed Jun 18, 2024
1 parent d439386 commit 1ba7e3d
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 36 deletions.
50 changes: 28 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,26 @@ go get github.com/elgohr/go-localstack
With SDK V2 (using EndpointResolverV2).
Please have a look at [resolvers](resolver.go) for a complete list of resolvers.
```go
func ExampleLocalstackWithContextSdkV2EndpointResolverV2() {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()

func ExampleLocalstackSdkV2EndpointResolverV2(t *testing.T) {
l, err := localstack.NewInstance()
if err != nil {
log.Fatalf("Could not connect to Docker %v", err)
t.Fatalf("Could not connect to Docker %v", err)
}
if err := l.StartWithContext(ctx); err != nil {
log.Fatalf("Could not start localstack %v", err)
if err := l.Start(); err != nil {
t.Fatalf("Could not start localstack %v", err)
}
t.Cleanup(func() {
if err := l.Stop(); err != nil {
t.Fatalf("Could not stop localstack %v", err)
}
})

cfg, err := config.LoadDefaultConfig(ctx,
config.WithRegion("us-east-1"),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider("dummy", "dummy", "dummy")),
)
if err != nil {
log.Fatalf("Could not get config %v", err)
t.Fatalf("Could not get config %v", err)
}
resolver := localstack.NewDynamoDbResolverV2(i)
client := dynamodb.NewFromConfig(cfg, dynamodb.WithEndpointResolverV2(resolver))
Expand All @@ -50,17 +52,19 @@ func ExampleLocalstackWithContextSdkV2EndpointResolverV2() {

With SDK V2 (using EndpointResolverV1)
```go
func ExampleLocalstackWithContextSdkV2() {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()

func ExampleLocalstackSdkV2(t *testing.T) {
l, err := localstack.NewInstance()
if err != nil {
log.Fatalf("Could not connect to Docker %v", err)
t.Fatalf("Could not connect to Docker %v", err)
}
if err := l.StartWithContext(ctx); err != nil {
log.Fatalf("Could not start localstack %v", err)
if err := l.Start(); err != nil {
t.Fatalf("Could not start localstack %v", err)
}
t.Cleanup(func() {
if err := l.Stop(); err != nil {
t.Fatalf("Could not stop localstack %v", err)
}
})

cfg, err := config.LoadDefaultConfig(ctx,
config.WithRegion("us-east-1"),
Expand All @@ -75,7 +79,7 @@ func ExampleLocalstackWithContextSdkV2() {
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider("dummy", "dummy", "dummy")),
)
if err != nil {
log.Fatalf("Could not get config %v", err)
t.Fatalf("Could not get config %v", err)
}

myTestWithV2(cfg)
Expand All @@ -85,16 +89,18 @@ func ExampleLocalstackWithContextSdkV2() {
With SDK V1
```go
func TestWithLocalStack(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()

l, err := localstack.NewInstance()
if err != nil {
log.Fatalf("Could not connect to Docker %v", err)
t.Fatalf("Could not connect to Docker %v", err)
}
if err := l.StartWithContext(ctx); err != nil {
log.Fatalf("Could not start localstack %v", err)
if err := l.Start(); err != nil {
t.Fatalf("Could not start localstack %v", err)
}
t.Cleanup(func() {
if err := l.Stop(); err != nil {
t.Fatalf("Could not stop localstack %v", err)
}
})

myTestWith(&aws.Config{
Credentials: credentials.NewStaticCredentials("not", "empty", ""),
Expand Down
43 changes: 41 additions & 2 deletions exampleV2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package localstack_test

import (
"context"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"log"
"time"

Expand All @@ -27,17 +28,22 @@ import (
"github.com/elgohr/go-localstack"
)

func ExampleLocalstackWithContextSdkV2() {
func ExampleLocalstackSdkV2() {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()

l, err := localstack.NewInstance()
if err != nil {
log.Fatalf("Could not connect to Docker %v", err)
}
if err := l.StartWithContext(ctx); err != nil {
if err := l.Start(); err != nil {
log.Fatalf("Could not start localstack %v", err)
}
defer func() { // this should be t.Cleanup for better stability
if err := l.Stop(); err != nil {
log.Fatalf("Could not stop localstack %v", err)
}
}()

cfg, err := config.LoadDefaultConfig(ctx,
config.WithRegion("us-east-1"),
Expand All @@ -58,4 +64,37 @@ func ExampleLocalstackWithContextSdkV2() {
myTestWithV2(cfg)
}

func ExampleLocalstackSdkV2WithEndpointResolverV2() {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()

l, err := localstack.NewInstance()
if err != nil {
log.Fatalf("Could not connect to Docker %v", err)
}
if err := l.Start(); err != nil {
log.Fatalf("Could not start localstack %v", err)
}
defer func() { // this should be t.Cleanup for better stability
if err := l.Stop(); err != nil {
log.Fatalf("Could not stop localstack %v", err)
}
}()

cfg, err := config.LoadDefaultConfig(ctx,
config.WithRegion("us-east-1"),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider("dummy", "dummy", "dummy")),
)
if err != nil {
log.Fatalf("Could not get config %v", err)
}

resolver := localstack.NewDynamoDbResolverV2(l)
client := dynamodb.NewFromConfig(cfg, dynamodb.WithEndpointResolverV2(resolver))

myTestWithV2Client(client)
}

func myTestWithV2(_ aws.Config) {}

func myTestWithV2Client(_ *dynamodb.Client) {}
24 changes: 12 additions & 12 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,27 @@
package localstack_test

import (
"context"
"log"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/endpoints"
"log"

"github.com/elgohr/go-localstack"
)

func ExampleLocalstackWithContext() {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()

l, err := localstack.NewInstance()
if err != nil {
log.Fatalf("Could not connect to Docker %v", err)
}
if err := l.StartWithContext(ctx); err != nil {
if err := l.Start(); err != nil {
log.Fatalf("Could not start localstack %v", err)
}
defer func() { // this should be t.Cleanup for better stability
if err := l.Stop(); err != nil {
log.Fatalf("Could not stop localstack %v", err)
}
}()

myTestWith(&aws.Config{
Credentials: credentials.NewStaticCredentials("not", "empty", ""),
Expand All @@ -55,17 +54,18 @@ func ExampleLocalstack() {
if err := l.Start(); err != nil {
log.Fatalf("Could not start localstack %v", err)
}
defer func() { // this should be t.Cleanup for better stability
if err := l.Stop(); err != nil {
log.Fatalf("Could not stop localstack %v", err)
}
}()

myTestWith(&aws.Config{
Credentials: credentials.NewStaticCredentials("not", "empty", ""),
DisableSSL: aws.Bool(true),
Region: aws.String(endpoints.UsWest1RegionID),
Endpoint: aws.String(l.Endpoint(localstack.SQS)),
})

if err := l.Stop(); err != nil {
log.Fatalf("Could not stop localstack %v", err)
}
}

func myTestWith(_ *aws.Config) {}

0 comments on commit 1ba7e3d

Please sign in to comment.