(t *testing.T)
| 42 | ) |
| 43 | |
| 44 | func TestComposeUp(t *testing.T) { |
| 45 | testCase := nerdtest.Setup() |
| 46 | |
| 47 | testCase.Setup = func(data test.Data, helpers test.Helpers) { |
| 48 | hostPort, err := portlock.Acquire(0) |
| 49 | if err != nil { |
| 50 | helpers.T().Log(fmt.Sprintf("Failed to acquire port: %v", err)) |
| 51 | helpers.T().FailNow() |
| 52 | } |
| 53 | |
| 54 | composeYAML := fmt.Sprintf(` |
| 55 | services: |
| 56 | wordpress: |
| 57 | image: %s |
| 58 | restart: always |
| 59 | ports: |
| 60 | - %d:80 |
| 61 | environment: |
| 62 | WORDPRESS_DB_HOST: db |
| 63 | WORDPRESS_DB_USER: exampleuser |
| 64 | WORDPRESS_DB_PASSWORD: examplepass |
| 65 | WORDPRESS_DB_NAME: exampledb |
| 66 | volumes: |
| 67 | - wordpress:/var/www/html |
| 68 | db: |
| 69 | image: %s |
| 70 | restart: always |
| 71 | environment: |
| 72 | MYSQL_DATABASE: exampledb |
| 73 | MYSQL_USER: exampleuser |
| 74 | MYSQL_PASSWORD: examplepass |
| 75 | MYSQL_RANDOM_ROOT_PASSWORD: '1' |
| 76 | volumes: |
| 77 | - db:/var/lib/mysql |
| 78 | |
| 79 | volumes: |
| 80 | wordpress: |
| 81 | db: |
| 82 | `, testutil.WordpressImage, hostPort, testutil.MariaDBImage) |
| 83 | |
| 84 | composePath := data.Temp().Save(composeYAML, "compose.yaml") |
| 85 | |
| 86 | projectName := filepath.Base(filepath.Dir(composePath)) |
| 87 | t.Logf("projectName=%q", projectName) |
| 88 | |
| 89 | wordpressContainerName := serviceparser.DefaultContainerName(projectName, "wordpress", "1") |
| 90 | dbContainerName := serviceparser.DefaultContainerName(projectName, "db", "1") |
| 91 | |
| 92 | data.Labels().Set("hostPort", strconv.Itoa(hostPort)) |
| 93 | data.Labels().Set("composeYAML", composePath) |
| 94 | data.Labels().Set("projectName", projectName) |
| 95 | data.Labels().Set("wordpressContainerName", wordpressContainerName) |
| 96 | data.Labels().Set("dbContainerName", dbContainerName) |
| 97 | |
| 98 | helpers.Ensure("compose", "-f", composePath, "up", "-d") |
| 99 | nerdtest.EnsureContainerStarted(helpers, wordpressContainerName) |
| 100 | nerdtest.EnsureContainerStarted(helpers, dbContainerName) |
| 101 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…