MCPcopy Create free account
hub / github.com/coder/envbuilder / TestDockerfileBuildContext

Function TestDockerfileBuildContext

integration/integration_test.go:1545–1630  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1543}
1544
1545func TestDockerfileBuildContext(t *testing.T) {
1546 t.Parallel()
1547
1548 inclFile := "myfile"
1549 dockerfile := fmt.Sprintf(`FROM %s
1550COPY %s .`, testImageAlpine, inclFile)
1551
1552 tests := []struct {
1553 name string
1554 files map[string]string
1555 dockerfilePath string
1556 buildContextPath string
1557 expectedErr string
1558 }{
1559 {
1560 // Dockerfile & build context are in the same dir, copying inclFile should work.
1561 name: "same build context (default)",
1562 files: map[string]string{
1563 "Dockerfile": dockerfile,
1564 inclFile: "...",
1565 },
1566 dockerfilePath: "Dockerfile",
1567 buildContextPath: "", // use default
1568 expectedErr: "", // expect no errors
1569 },
1570 {
1571 // Dockerfile & build context are not in the same dir, build context is still the default; this should fail
1572 // to copy inclFile since it is not in the same dir as the Dockerfile.
1573 name: "different build context (default)",
1574 files: map[string]string{
1575 "a/Dockerfile": dockerfile,
1576 "a/" + inclFile: "...",
1577 },
1578 dockerfilePath: "a/Dockerfile",
1579 buildContextPath: "", // use default
1580 expectedErr: inclFile + ": no such file or directory",
1581 },
1582 {
1583 // Dockerfile & build context are not in the same dir, but inclFile is in the default build context dir;
1584 // this should allow inclFile to be copied. This is probably not desirable though?
1585 name: "different build context (default, different content roots)",
1586 files: map[string]string{
1587 "a/Dockerfile": dockerfile,
1588 inclFile: "...",
1589 },
1590 dockerfilePath: "a/Dockerfile",
1591 buildContextPath: "", // use default
1592 expectedErr: "",
1593 },
1594 {
1595 // Dockerfile is not in the default build context dir, but the build context has been overridden; this should
1596 // allow inclFile to be copied.
1597 name: "different build context (custom)",
1598 files: map[string]string{
1599 "a/Dockerfile": dockerfile,
1600 "a/" + inclFile: "...",
1601 },
1602 dockerfilePath: "a/Dockerfile",

Callers

nothing calls this directly

Calls 3

CreateGitServerFunction · 0.92
runEnvbuilderFunction · 0.85
envbuilderEnvFunction · 0.85

Tested by

no test coverage detected