Documentation ¶
Overview ¶
Package azurite provides a Gnomock Preset for azurite project It allows to easily setup local Blobstorage for testing
Index ¶
Examples ¶
Constants ¶
const ( BlobServicePort = "blob" QueueServicePort = "queue" TableServicePort = "table" )
const ( ConnectionStringFormat = "DefaultEndpointsProtocol=http;AccountName=%s;AccountKey=%s;BlobEndpoint=http://%s/%s;" AccountName = "devstoreaccount1" AccountKey = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==" DefaultVersion = "3.22.0" )
Variables ¶
This section is empty.
Functions ¶
func Preset ¶
Preset creates a new azurite preset to use with gnomock.Start. See package docs for a list of exposed ports.
Example ¶
package main import ( "context" "fmt" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob" "github.com/orlangure/gnomock/preset/azurite" "github.com/orlangure/gnomock" ) func main() { p := azurite.Preset( azurite.WithVersion(azurite.DefaultVersion), ) c, startErr := gnomock.Start(p) if startErr != nil { fmt.Println("Starting azurite gnomock failed ", startErr) return } defer func() { _ = gnomock.Stop(c) }() connString := fmt.Sprintf( azurite.ConnectionStringFormat, azurite.AccountName, azurite.AccountKey, c.Address(azurite.BlobServicePort), azurite.AccountName) ctx := context.Background() azblobClient, connectError := azblob.NewClientFromConnectionString(connString, nil) if connectError != nil { fmt.Println("Connecting to azurite failed ", connectError) return } containerName := "foo" _, createContainerError := azblobClient.CreateContainer(ctx, containerName, nil) if createContainerError != nil { fmt.Println("Creating azure container failed ", createContainerError) return } pages := 0 pager := azblobClient.NewListBlobsFlatPager(containerName, nil) for pager.More() { resp, _ := pager.NextPage(context.Background()) fmt.Println("keys before:", len(resp.Segment.BlobItems)) pages++ } fmt.Println("pages before:", pages) blobName := "bar" _, _ = azblobClient.UploadBuffer(ctx, containerName, blobName, []byte{15, 16, 17}, nil) pages = 0 pager = azblobClient.NewListBlobsFlatPager(containerName, nil) for pager.More() { resp, _ := pager.NextPage(context.Background()) fmt.Println("keys after:", len(resp.Segment.BlobItems)) for _, v := range resp.Segment.BlobItems { fmt.Println("filename:", *v.Name) } pages++ } fmt.Println("pages after:", 1) }
Output: keys before: 0 pages before: 1 keys after: 1 filename: bar pages after: 1
Types ¶
type Option ¶
type Option func(*P)
Option is an optional configuration of this Gnomock preset. Use available Options to configure the container.
func WithBlobstorageFiles ¶
WithBlobstorageFiles sets up Blobstorage service running in azurite with the contents of `path` directory. The first level children of `path` must be directories, their names will be used to create containers. Below them, all the files in any other directories, these files will be uploaded as-is.
For example, if you put your test files in testdata/my-container/dir/, Gnomock will create "my-container" for you, and pull "dir" with all its contents into this container.
type P ¶
P is a Gnomock Preset blobstorage implementation.
func (*P) Ports ¶
func (p *P) Ports() gnomock.NamedPorts
Ports returns ports that should be used to access this container.