Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/elgohr/go-localstack
Go Wrapper for using localstack
https://github.com/elgohr/go-localstack
aws cloudformation cloudwatch dynamodb ec2 elasticsearch go golang golang-library iam lambda localstack redshift route53 s3 secretsmanager ses sns sqs testing
Last synced: 12 days ago
JSON representation
Go Wrapper for using localstack
- Host: GitHub
- URL: https://github.com/elgohr/go-localstack
- Owner: elgohr
- License: apache-2.0
- Created: 2020-03-18T07:13:02.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-04-29T01:49:56.000Z (6 months ago)
- Last Synced: 2024-05-01T12:35:20.529Z (6 months ago)
- Topics: aws, cloudformation, cloudwatch, dynamodb, ec2, elasticsearch, go, golang, golang-library, iam, lambda, localstack, redshift, route53, s3, secretsmanager, ses, sns, sqs, testing
- Language: Go
- Homepage:
- Size: 9.94 MB
- Stars: 75
- Watchers: 3
- Forks: 18
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - go-localstack - Tool for using localstack in AWS testing. (Testing / Mock)
- awesome-go-extra - go-localstack - 03-18T07:13:02Z|2022-08-25T00:31:04Z| (Testing / Mock)
- awesome-localstack - Go Client
- awesome-localstack - Go Client
README
# go-localstack
[![Test](https://github.com/elgohr/go-localstack/workflows/Test/badge.svg)](https://github.com/elgohr/go-localstack/actions/workflows/test.yml)
[![codecov](https://codecov.io/gh/elgohr/go-localstack/branch/main/graph/badge.svg)](https://codecov.io/gh/elgohr/go-localstack)
[![CodeQL](https://github.com/elgohr/go-localstack/workflows/CodeQL/badge.svg)](https://github.com/elgohr/go-localstack/actions/workflows/codeql-analysis.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/elgohr/go-localstack)](https://goreportcard.com/report/github.com/elgohr/go-localstack)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/elgohr/go-localstack)](https://pkg.go.dev/github.com/elgohr/go-localstack)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/gojp/goreportcard/blob/master/LICENSE)Go Wrapper for using [localstack](https://github.com/localstack/localstack) in go testing
# Installation
Please make sure that you have Docker installed.
```bash
go get github.com/elgohr/go-localstack
```# Usage
With SDK V2 (using EndpointResolverV2).
Please have a look at [resolvers](resolver.go) for a complete list of resolvers.
```go
func ExampleLocalstackSdkV2EndpointResolverV2(t *testing.T) {
l, err := localstack.NewInstance()
if err != nil {
t.Fatalf("Could not connect to Docker %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 {
t.Fatalf("Could not get config %v", err)
}
resolver := localstack.NewDynamoDbResolverV2(i)
client := dynamodb.NewFromConfig(cfg, dynamodb.WithEndpointResolverV2(resolver))
myTestWithV2Client(client)
}
```With SDK V2 (using EndpointResolverV1)
```go
func ExampleLocalstackSdkV2(t *testing.T) {
l, err := localstack.NewInstance()
if err != nil {
t.Fatalf("Could not connect to Docker %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.WithEndpointResolverWithOptions(aws.EndpointResolverWithOptionsFunc(func(_, _ string, _ ...interface{}) (aws.Endpoint, error) {
return aws.Endpoint{
PartitionID: "aws",
URL: l.EndpointV2(localstack.SQS),
SigningRegion: "us-east-1",
HostnameImmutable: true,
}, nil
})),
config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider("dummy", "dummy", "dummy")),
)
if err != nil {
t.Fatalf("Could not get config %v", err)
}
myTestWithV2(cfg)
}
```With SDK V1
```go
func TestWithLocalStack(t *testing.T) {
l, err := localstack.NewInstance()
if err != nil {
t.Fatalf("Could not connect to Docker %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", ""),
DisableSSL: aws.Bool(true),
Region: aws.String(endpoints.UsWest1RegionID),
Endpoint: aws.String(l.Endpoint(localstack.SQS)),
})
}
```