Categorygithub.com/elgohr/go-localstack
modulepackage
1.0.122
Repository: https://github.com/elgohr/go-localstack.git
Documentation: pkg.go.dev

# README

go-localstack

Test codecov CodeQL Go Report Card PkgGoDev License

Go Wrapper for using localstack in go testing

Installation

Please make sure that you have Docker installed.

go get github.com/elgohr/go-localstack

Usage

With SDK V2 (using EndpointResolverV2). Please have a look at resolvers for a complete list of resolvers.

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)

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

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)),
    })
}

# Functions

NewCloudformationResolverV2 resolves the services ResolverV2 endpoint.
NewCloudwatchEventsResolverV2 resolves the services ResolverV2 endpoint.
NewCloudwatchLogsResolverV2 resolves the services ResolverV2 endpoint.
NewCloudwatchResolverV2 resolves the services ResolverV2 endpoint.
NewDynamoDbResolverV2 resolves the services ResolverV2 endpoint.
NewDynamoDbStreamsResolverV2 resolves the services ResolverV2 endpoint.
NewEc2ResolverV2 resolves the services ResolverV2 endpoint.
NewElasticSearchResolverV2 resolves the services ResolverV2 endpoint.
NewFirehoseResolverV2 resolves the services ResolverV2 endpoint.
NewIamResolverV2 resolves the services ResolverV2 endpoint.
NewInstance creates a new Instance Fails when Docker is not reachable.
NewInstanceCtx is NewInstance, but with Context.
NewKinesisResolverV2 resolves the services ResolverV2 endpoint.
NewLambdaResolverV2 resolves the services ResolverV2 endpoint.
NewRedshiftResolverV2 resolves the services ResolverV2 endpoint.
NewRoute53ResolverV2 resolves the services ResolverV2 endpoint.
NewS3ResolverV2 resolves the services ResolverV2 endpoint.
NewSecretsManagerResolverV2 resolves the services ResolverV2 endpoint.
NewSesResolverV2 resolves the services ResolverV2 endpoint.
NewSnsResolverV2 resolves the services ResolverV2 endpoint.
NewSqsResolverV2 resolves the services ResolverV2 endpoint.
NewSsmResolverV2 resolves the services ResolverV2 endpoint.
NewStepFunctionsResolverV2 resolves the services ResolverV2 endpoint.
NewStsResolverV2 resolves the services ResolverV2 endpoint.
WithClientFromEnv configures the instance to use a client that respects environment variables.
WithClientFromEnvCtx like WithClientFromEnv but with context.
WithLabels configures the labels that will be applied on the instance.
WithLogger configures the instance to use the specified logger.
WithTimeout configures the timeout for terminating the localstack instance.
WithVersion configures the instance to use a specific version of localstack.

# Variables

AvailableServices provides a map of all services for faster searches.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.
Supported AWS/localstack services.

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Instance manages the localstack.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Service represents an AWS service.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

InstanceOption is an option that controls the behaviour of localstack.