Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithConfigFile ¶
func WithConfigFile(hostPath string) testcontainers.CustomizeRequestOption
WithConfigFile mounts a custom nginx.conf file at /etc/nginx/nginx.conf in the container. The hostPath must be an absolute path to the configuration file on the host.
func WithCustomConfig ¶
func WithCustomConfig(hostPath string) testcontainers.CustomizeRequestOption
WithCustomConfig mounts a configuration snippet at /etc/nginx/conf.d/default.conf in the container. The hostPath must be an absolute path to the configuration file on the host.
Types ¶
type Container ¶
type Container struct {
testcontainers.Container
}
Container represents the Nginx 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 Nginx container type.
Example ¶
package main
import (
"context"
"fmt"
"log"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/nginx"
)
func main() {
// runNginxContainer {
ctx := context.Background()
nginxContainer, err := nginx.Run(ctx, "nginx:1.25")
defer func() {
if err := testcontainers.TerminateContainer(nginxContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to start container: %s", err)
return
}
// }
state, err := nginxContainer.State(ctx)
if err != nil {
log.Printf("failed to get container state: %s", err)
return
}
fmt.Println(state.Running)
}
Output: true
Example (HttpEndpoint) ¶
package main
import (
"context"
"fmt"
"log"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/nginx"
)
func main() {
// httpEndpointExample {
ctx := context.Background()
nginxContainer, err := nginx.Run(ctx, "nginx:1.25")
defer func() {
if err := testcontainers.TerminateContainer(nginxContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to start container: %s", err)
return
}
httpEndpoint, err := nginxContainer.HTTPEndpoint(ctx)
if err != nil {
log.Printf("failed to get HTTP endpoint: %s", err)
return
}
// }
_ = httpEndpoint
fmt.Println("got http endpoint")
}
Output: got http endpoint
func (*Container) HTTPEndpoint ¶
HTTPEndpoint returns the HTTP endpoint of the Nginx container, in the form "http://host:port".
func (*Container) HTTPSEndpoint ¶
HTTPSEndpoint returns the HTTPS endpoint of the Nginx container, in the form "https://host:port".