Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 21 additions & 113 deletions e2e/tests/configapply/configapply.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,12 @@ var _ = ginkgo.Describe(
framework.ExpectNoError(err)
})

ginkgo.It("should execute postCreateCommand in a running container",
func(ctx context.Context) {
containerID := startAlpineContainer(ctx)
ginkgo.DeferCleanup(removeContainer, containerID)

tmpDir, err := framework.CreateTempDir()
framework.ExpectNoError(err)
ginkgo.DeferCleanup(framework.CleanupTempDir, initialDir, tmpDir)

devcontainerJSON := map[string]any{
imageKey: alpineImage,
postCreateCommandKey: "touch /tmp/setup-test-marker",
}
writeDevcontainerJSON(tmpDir, devcontainerJSON)
lifecycleHookTimeout := ginkgo.SpecTimeout(framework.TimeoutShort())

f := framework.NewDefaultFramework(initialDir + "/bin")
_, _, err = f.ExecCommandCapture(ctx, []string{
configGroup, applyCommand,
containerFlag, containerID,
configFlag, filepath.Join(tmpDir, ".devcontainer", devcontainerFn),
})
framework.ExpectNoError(err)

out := dockerExecInContainer(ctx, containerID, "cat", "/tmp/setup-test-marker")
gomega.Expect(out).To(gomega.BeEmpty())
}, ginkgo.SpecTimeout(framework.TimeoutShort()))

ginkgo.It("should execute postStartCommand in a running container",
func(ctx context.Context) {
// Empty table text keeps spec names identical to the standalone Its this replaces.
ginkgo.DescribeTable(
"",
func(ctx context.Context, hookKey, markerPath string) {
containerID := startAlpineContainer(ctx)
ginkgo.DeferCleanup(removeContainer, containerID)

Expand All @@ -76,8 +53,8 @@ var _ = ginkgo.Describe(
ginkgo.DeferCleanup(framework.CleanupTempDir, initialDir, tmpDir)

devcontainerJSON := map[string]any{
imageKey: alpineImage,
"postStartCommand": "touch /tmp/poststart-marker",
imageKey: alpineImage,
hookKey: "touch " + markerPath,
}
writeDevcontainerJSON(tmpDir, devcontainerJSON)

Expand All @@ -89,9 +66,21 @@ var _ = ginkgo.Describe(
})
framework.ExpectNoError(err)

out := dockerExecInContainer(ctx, containerID, "cat", "/tmp/poststart-marker")
out := dockerExecInContainer(ctx, containerID, "cat", markerPath)
gomega.Expect(out).To(gomega.BeEmpty())
}, ginkgo.SpecTimeout(framework.TimeoutShort()))
},
ginkgo.EntryDescription("should execute %[1]s in a running container"),
ginkgo.Entry(nil, postCreateCommandKey, "/tmp/setup-test-marker", lifecycleHookTimeout),
ginkgo.Entry(nil, "postStartCommand", "/tmp/poststart-marker", lifecycleHookTimeout),
ginkgo.Entry(nil, "onCreateCommand", "/tmp/oncreate-marker", lifecycleHookTimeout),
ginkgo.Entry(
nil,
"updateContentCommand",
"/tmp/updatecontent-marker",
lifecycleHookTimeout,
),
ginkgo.Entry(nil, "postAttachCommand", "/tmp/postattach-marker", lifecycleHookTimeout),
)

ginkgo.It("should pass containerEnv to lifecycle commands",
func(ctx context.Context) {
Expand Down Expand Up @@ -121,87 +110,6 @@ var _ = ginkgo.Describe(
gomega.Expect(strings.TrimSpace(out)).To(gomega.Equal("hello_world"))
}, ginkgo.SpecTimeout(framework.TimeoutShort()))

ginkgo.It("should execute onCreateCommand in a running container",
func(ctx context.Context) {
containerID := startAlpineContainer(ctx)
ginkgo.DeferCleanup(removeContainer, containerID)

tmpDir, err := framework.CreateTempDir()
framework.ExpectNoError(err)
ginkgo.DeferCleanup(framework.CleanupTempDir, initialDir, tmpDir)

devcontainerJSON := map[string]any{
imageKey: alpineImage,
"onCreateCommand": "touch /tmp/oncreate-marker",
}
writeDevcontainerJSON(tmpDir, devcontainerJSON)

f := framework.NewDefaultFramework(initialDir + "/bin")
_, _, err = f.ExecCommandCapture(ctx, []string{
configGroup, applyCommand,
containerFlag, containerID,
configFlag, filepath.Join(tmpDir, ".devcontainer", devcontainerFn),
})
framework.ExpectNoError(err)

out := dockerExecInContainer(ctx, containerID, "cat", "/tmp/oncreate-marker")
gomega.Expect(out).To(gomega.BeEmpty())
}, ginkgo.SpecTimeout(framework.TimeoutShort()))

ginkgo.It("should execute updateContentCommand in a running container",
func(ctx context.Context) {
containerID := startAlpineContainer(ctx)
ginkgo.DeferCleanup(removeContainer, containerID)

tmpDir, err := framework.CreateTempDir()
framework.ExpectNoError(err)
ginkgo.DeferCleanup(framework.CleanupTempDir, initialDir, tmpDir)

devcontainerJSON := map[string]any{
imageKey: alpineImage,
"updateContentCommand": "touch /tmp/updatecontent-marker",
}
writeDevcontainerJSON(tmpDir, devcontainerJSON)

f := framework.NewDefaultFramework(initialDir + "/bin")
_, _, err = f.ExecCommandCapture(ctx, []string{
configGroup, applyCommand,
containerFlag, containerID,
configFlag, filepath.Join(tmpDir, ".devcontainer", devcontainerFn),
})
framework.ExpectNoError(err)

out := dockerExecInContainer(ctx, containerID, "cat", "/tmp/updatecontent-marker")
gomega.Expect(out).To(gomega.BeEmpty())
}, ginkgo.SpecTimeout(framework.TimeoutShort()))

ginkgo.It("should execute postAttachCommand in a running container",
func(ctx context.Context) {
containerID := startAlpineContainer(ctx)
ginkgo.DeferCleanup(removeContainer, containerID)

tmpDir, err := framework.CreateTempDir()
framework.ExpectNoError(err)
ginkgo.DeferCleanup(framework.CleanupTempDir, initialDir, tmpDir)

devcontainerJSON := map[string]any{
imageKey: alpineImage,
"postAttachCommand": "touch /tmp/postattach-marker",
}
writeDevcontainerJSON(tmpDir, devcontainerJSON)

f := framework.NewDefaultFramework(initialDir + "/bin")
_, _, err = f.ExecCommandCapture(ctx, []string{
configGroup, applyCommand,
containerFlag, containerID,
configFlag, filepath.Join(tmpDir, ".devcontainer", devcontainerFn),
})
framework.ExpectNoError(err)

out := dockerExecInContainer(ctx, containerID, "cat", "/tmp/postattach-marker")
gomega.Expect(out).To(gomega.BeEmpty())
}, ginkgo.SpecTimeout(framework.TimeoutShort()))

ginkgo.It("should pass remoteEnv to lifecycle commands",
func(ctx context.Context) {
containerID := startAlpineContainer(ctx)
Expand Down
Loading