github.com/darmach/terratest@v0.34.8-0.20210517103231-80931f95e3ff/test/docker_hello_world_example_test.go (about)

     1  package test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/gruntwork-io/terratest/modules/docker"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestDockerHelloWorldExample(t *testing.T) {
    11  	// website::tag::1:: Configure the tag to use on the Docker image.
    12  	tag := "gruntwork/docker-hello-world-example"
    13  	buildOptions := &docker.BuildOptions{
    14  		Tags: []string{tag},
    15  	}
    16  
    17  	// website::tag::2:: Build the Docker image.
    18  	docker.Build(t, "../examples/docker-hello-world-example", buildOptions)
    19  
    20  	// website::tag::3:: Run the Docker image, read the text file from it, and make sure it contains the expected output.
    21  	opts := &docker.RunOptions{Command: []string{"cat", "/test.txt"}}
    22  	output := docker.Run(t, tag, opts)
    23  	assert.Equal(t, "Hello, World!", output)
    24  }