github.com/mponton/terratest@v0.44.0/modules/docker/docker_compose_test.go (about)

     1  package docker
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  func TestDockerComposeWithBuildKit(t *testing.T) {
    10  	t.Parallel()
    11  
    12  	testToken := "testToken"
    13  	dockerOptions := &Options{
    14  		// Directory where docker-compose.yml lives
    15  		WorkingDir: "../../test/fixtures/docker-compose-with-buildkit",
    16  
    17  		// Configure the port the web app will listen on and the text it will return using environment variables
    18  		EnvVars: map[string]string{
    19  			"GITHUB_OAUTH_TOKEN": testToken,
    20  		},
    21  		EnableBuildKit: true,
    22  	}
    23  	out := RunDockerCompose(t, dockerOptions, "build", "--no-cache")
    24  	out = RunDockerCompose(t, dockerOptions, "up")
    25  
    26  	require.Contains(t, out, testToken)
    27  }
    28  
    29  func TestDockerComposeWithCustomProjectName(t *testing.T) {
    30  	t.Parallel()
    31  
    32  	tests := []struct {
    33  		name     string
    34  		options  *Options
    35  		expected string
    36  	}{
    37  		{
    38  			name: "Testing ",
    39  			options: &Options{
    40  				WorkingDir: "../../test/fixtures/docker-compose-with-custom-project-name",
    41  			},
    42  			expected: "testdockercomposewithcustomprojectname",
    43  		},
    44  		{
    45  			name: "Testing",
    46  			options: &Options{
    47  				WorkingDir:  "../../test/fixtures/docker-compose-with-custom-project-name",
    48  				ProjectName: "testingProjectName",
    49  			},
    50  			expected: "testingprojectname",
    51  		},
    52  	}
    53  
    54  	for _, test := range tests {
    55  		t.Run(test.name, func(t *testing.T) {
    56  			t.Log(test.name)
    57  
    58  			output := RunDockerCompose(t, test.options, "up", "-d")
    59  			defer RunDockerCompose(t, test.options, "down", "--remove-orphans", "--timeout", "2")
    60  
    61  			require.Contains(t, output, test.expected)
    62  		})
    63  	}
    64  }