(t *testing.T)
| 133 | } |
| 134 | |
| 135 | func TestComposeUpBuild(t *testing.T) { |
| 136 | testCase := nerdtest.Setup() |
| 137 | |
| 138 | testCase.Require = nerdtest.Build |
| 139 | |
| 140 | testCase.Setup = func(data test.Data, helpers test.Helpers) { |
| 141 | hostPort, err := portlock.Acquire(0) |
| 142 | if err != nil { |
| 143 | helpers.T().Log(fmt.Sprintf("Failed to acquire port: %v", err)) |
| 144 | helpers.T().FailNow() |
| 145 | } |
| 146 | |
| 147 | composeYAML := fmt.Sprintf(` |
| 148 | services: |
| 149 | web: |
| 150 | build: . |
| 151 | ports: |
| 152 | - %d:80 |
| 153 | `, hostPort) |
| 154 | dockerfile := fmt.Sprintf(`FROM %s |
| 155 | COPY index.html /usr/share/nginx/html/index.html |
| 156 | `, testutil.NginxAlpineImage) |
| 157 | indexHTML := data.Identifier("indexHTML") |
| 158 | |
| 159 | composePath := data.Temp().Save(composeYAML, "compose.yaml") |
| 160 | data.Temp().Save(dockerfile, "Dockerfile") |
| 161 | data.Temp().Save(indexHTML, "index.html") |
| 162 | |
| 163 | projectName := filepath.Base(filepath.Dir(composePath)) |
| 164 | t.Logf("projectName=%q", projectName) |
| 165 | |
| 166 | data.Labels().Set("hostPort", strconv.Itoa(hostPort)) |
| 167 | data.Labels().Set("composeYAML", composePath) |
| 168 | data.Labels().Set("indexHTML", data.Temp().Path("index.html")) |
| 169 | |
| 170 | helpers.Ensure("compose", "-f", composePath, "up", "-d", "--build") |
| 171 | nerdtest.EnsureContainerStarted(helpers, serviceparser.DefaultContainerName(projectName, "web", "1")) |
| 172 | } |
| 173 | |
| 174 | testCase.SubTests = []*test.Case{ |
| 175 | { |
| 176 | Description: "HTTP request to the web container", |
| 177 | Expected: func(data test.Data, helpers test.Helpers) *test.Expected { |
| 178 | return &test.Expected{ |
| 179 | Output: func(stdout string, t tig.T) { |
| 180 | host := fmt.Sprintf("http://127.0.0.1:%s", data.Labels().Get("hostPort")) |
| 181 | resp, err := nettestutil.HTTPGet(host, 5, false) |
| 182 | assert.NilError(t, err) |
| 183 | respBody, err := io.ReadAll(resp.Body) |
| 184 | assert.NilError(t, err) |
| 185 | t.Log(fmt.Sprintf("respBody=%q", respBody)) |
| 186 | assert.Assert(t, strings.Contains(string(respBody), data.Labels().Get("indexHTML"))) |
| 187 | }, |
| 188 | } |
| 189 | }, |
| 190 | }, |
| 191 | } |
| 192 |
nothing calls this directly
no test coverage detected
searching dependent graphs…