Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Container ¶
type Container struct {
testcontainers.Container
}
Container represents the Memcached container type used in the module
func Run ¶
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error)
Run creates an instance of the Memcached container type
Example ¶
// runMemcachedContainer { ctx := context.Background() memcachedContainer, err := memcached.Run(ctx, "memcached:1.6-alpine") defer func() { if err := testcontainers.TerminateContainer(memcachedContainer); err != nil { log.Printf("failed to terminate container: %s", err) } }() if err != nil { log.Printf("failed to start container: %s", err) return } // } state, err := memcachedContainer.State(ctx) if err != nil { log.Printf("failed to get container state: %s", err) return } fmt.Println(state.Running)
Output: true
Example (Connect) ¶
ctx := context.Background() memcachedContainer, err := memcached.Run(ctx, "memcached:1.6-alpine") defer func() { if err := testcontainers.TerminateContainer(memcachedContainer); err != nil { log.Printf("failed to terminate container: %s", err) } }() if err != nil { log.Printf("failed to start container: %s", err) return } // hostPort { hostPort, err := memcachedContainer.HostPort(ctx) if err != nil { log.Printf("failed to get host and port: %s", err) return } // } mc := memcache.New(hostPort) err = mc.Set(&memcache.Item{Key: "foo", Value: []byte("my value")}) if err != nil { log.Printf("failed to set item: %s", err) return } it, err := mc.Get("foo") if err != nil { log.Printf("failed to get item: %s", err) return } fmt.Println(string(it.Value))
Output: my value
Click to show internal directories.
Click to hide internal directories.