Skip to content

Commit

Permalink
feat: Update test helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
libmartinito committed May 17, 2024
1 parent 3057fa4 commit 41031a6
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 37 deletions.
43 changes: 25 additions & 18 deletions internal/test_helpers/course_definition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,31 @@ marketing:
to explore and learn for yourself.
stages:
- slug: "init"
- legacy_slug: "init"
slug: "je9"
name: "Execute a program"
difficulty: very_easy
description_md: |-
Your task is to implement a very basic version
Your task is to implement a very basic version
of [`docker run`](https://docs.docker.com/engine/reference/run/)</a>. It will
be executed similar to `docker run`:
```
your_docker run ubuntu:latest /usr/local/bin/docker-explorer echo hey
mydocker run alpine:latest /usr/local/bin/docker-explorer echo hey
```
[docker-explorer](https://github.com/codecrafters-io/docker-explorer) is a custom test program that exposes
commands like `echo` and `ls`.
For now, don't worry about pulling the `ubuntu:latest` image. We will just
execute a local program for this stage and print its output. You'll work on
For now, don't worry about pulling the `alpine:latest` image. We will just
execute a local program for this stage and print its output. You'll work on
pulling images from Docker Hub in stage 6.
marketing_md: |-
In this stage, you'll execute a program using `fork` + `exec`.
tester_source_code_url: "https://github.com/codecrafters-io/docker-tester/blob/18245703a5beed8ee0a7e1cbb7204a7ee3b3b5d1/internal/stage_basic_exec.go#L9"

- slug: "stdio"
- legacy_slug: "stdio"
slug: "kf3"
name: "Wireup stdout & stderr"
difficulty: easy
description_md: |-
Expand All @@ -99,9 +101,9 @@ stages:
Like the last stage, the tester will run your program like this:
```
your_docker run ubuntu:latest /usr/local/bin/docker-explorer echo hey
mydocker run alpine:latest /usr/local/bin/docker-explorer echo hey
```
To test this behaviour locally, you could use the `echo` + `echo_stderr`
commands that `docker-explorer` exposes. Run `docker-explorer --help` to
view usage.
Expand All @@ -110,14 +112,15 @@ stages:
them. The tester can't differentiate between debug logs and the actual
output!
Note: The [README]({{readme_url}}) contains setup
Note: The **README** in your repository contains setup
information for this stage and beyond (takes < 5 min).
marketing_md: |-
In this stage, you'll relay the child program's stdout & stderr to the
parent process.
tester_source_code_url: "https://github.com/codecrafters-io/docker-tester/blob/18245703a5beed8ee0a7e1cbb7204a7ee3b3b5d1/internal/stage_stdio.go#L9"

- slug: "exit_code"
- legacy_slug: "exit_code"
slug: "cn8"
name: "Handle exit codes"
difficulty: easy
description_md: |-
Expand All @@ -133,14 +136,15 @@ stages:
Just like the previous stage, the tester will run your program like this:
```
your_docker run ubuntu:latest /usr/local/bin/docker-explorer exit 1
mydocker run alpine:latest /usr/local/bin/docker-explorer exit 1
```
marketing_md: |-
In this stage, you'll wait for the child program's exit code and exit with
it.
tester_source_code_url: "https://github.com/codecrafters-io/docker-tester/blob/18245703a5beed8ee0a7e1cbb7204a7ee3b3b5d1/internal/stage_exit_code.go#L9"

- slug: "fs_isolation"
- legacy_slug: "fs_isolation"
slug: "if6"
name: "Filesystem isolation"
difficulty: medium
description_md: |-
Expand Down Expand Up @@ -188,14 +192,15 @@ stages:
Just like the previous stage, the tester will run your program like this:
```
your_docker run ubuntu:latest /usr/local/bin/docker-explorer ls /some_dir
mydocker run alpine:latest /usr/local/bin/docker-explorer ls /some_dir
```
marketing_md: |-
In this stage, you'll restrict a program's access to the host filesystem
by using [chroot](https://en.wikipedia.org/wiki/Chroot).
tester_source_code_url: "https://github.com/codecrafters-io/docker-tester/blob/18245703a5beed8ee0a7e1cbb7204a7ee3b3b5d1/internal/stage_fs_isolation.go#L8"

- slug: "process_isolation"
- legacy_slug: "process_isolation"
slug: "lu7"
name: "Process isolation"
difficulty: medium
description_md: |-
Expand All @@ -220,16 +225,18 @@ stages:
Just like the previous stage, the tester will run your program like this:
```
your_docker run ubuntu:latest /usr/local/bin/docker-explorer mypid
mydocker run alpine:latest /usr/local/bin/docker-explorer mypid
```
marketing_md: |-
In this stage, you'll restrict a program's access to the host's process
tree by using [PID
namespaces](http://man7.org/linux/man-pages/man7/pid_namespaces.7.html).
tester_source_code_url: "https://github.com/codecrafters-io/docker-tester/blob/18245703a5beed8ee0a7e1cbb7204a7ee3b3b5d1/internal/stage_process_isolation.go#L5"

- slug: "fetch_from_registry"
- legacy_slug: "fetch_from_registry"
slug: "hs1"
name: "Fetch an image from the Docker Registry"
should_skip_previous_stages_for_test_run: true
difficulty: hard
description_md: |-
Your docker implementation can now execute a program with a fair degree of
Expand All @@ -252,13 +259,13 @@ stages:
The tester will run your program like this:
```
your_docker run ubuntu:latest /bin/echo hey
mydocker run alpine:latest /bin/echo hey
```
The image used will be an [official
image](https://docs.docker.com/docker-hub/official_images/) from Docker
Hub. For example: [`alpine:latest`](https://hub.docker.com/_/alpine),
[`ubuntu:latest`](https://hub.docker.com/_/ubuntu),
[`alpine:latest`](https://hub.docker.com/_/alpine),
[`busybox:latest`](https://hub.docker.com/_/busybox). When interacting with the
Registry API, you'll need to prepend `library/` to the image names.
Expand Down
2 changes: 1 addition & 1 deletion internal/test_helpers/fixtures/basic_exec/failure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Debug = true

[stage-1] Running tests for Stage #1: init
[stage-1] Running tests for Stage #1: je9
[stage-1] Executing: ./your_docker.sh run <some_image> /usr/local/bin/docker-explorer echo 88398
[your_program] wrong
[stage-1] Checking if the command output was echo-ed..
Expand Down
2 changes: 1 addition & 1 deletion internal/test_helpers/fixtures/basic_exec/success
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Debug = true

[stage-1] Running tests for Stage #1: init
[stage-1] Running tests for Stage #1: je9
[stage-1] Executing: ./your_docker.sh run <some_image> /usr/local/bin/docker-explorer echo 88398
[your_program] 88398
[stage-1] Checking if the command output was echo-ed..
Expand Down
4 changes: 2 additions & 2 deletions internal/test_helpers/fixtures/exit_code/success
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Debug = true

[stage-2] Running tests for Stage #2: stdio
[stage-2] Running tests for Stage #2: kf3
[stage-2] Executing: ./your_docker.sh run <some_image> /usr/local/bin/docker-explorer echo 88398
[your_program] 88398
[stage-2] Checking if the string was echo-ed to stdout..
Expand All @@ -9,7 +9,7 @@ Debug = true
[stage-2] Checking if the string was echo-ed to stderr..
[stage-2] Test passed.

[stage-1] Running tests for Stage #1: init
[stage-1] Running tests for Stage #1: je9
[stage-1] Executing: ./your_docker.sh run <some_image> /usr/local/bin/docker-explorer echo 88398
[your_program] 88398
[stage-1] Checking if the command output was echo-ed..
Expand Down
2 changes: 1 addition & 1 deletion internal/test_helpers/fixtures/fetch_from_registry/failure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Debug = true

[stage-6] Running tests for Stage #6: fetch_from_registry
[stage-6] Running tests for Stage #6: hs1
[stage-6] Executing: ./your_docker.sh run alpine /bin/sh -c '/bin/ls /'
[your_program] Expected 'run <image> <command>' as the command! args: ["run" "alpine" "/bin/sh" "-c" "/bin/ls /"]
[stage-6] Expected 0 as exit code, got: 1
Expand Down
2 changes: 1 addition & 1 deletion internal/test_helpers/fixtures/fetch_from_registry/success
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Debug = true

[stage-1] Running tests for Stage #1: fetch_from_registry
[stage-1] Running tests for Stage #1: hs1
[stage-1] Executing: ./your_docker.sh run alpine /bin/sh -c '/bin/ls /'
[your_program] bin
[your_program] dev
Expand Down
2 changes: 1 addition & 1 deletion internal/test_helpers/fixtures/fs_isolation/failure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Debug = true

[stage-4] Running tests for Stage #4: fs_isolation
[stage-4] Running tests for Stage #4: if6
[stage-4] Created temp dir on host: /tmp/88398
[stage-4] Executing: ./your_docker.sh run <some_image> /usr/local/bin/docker-explorer ls /tmp/88398
[stage-4] (expecting that the directory won't be accessible)
Expand Down
8 changes: 4 additions & 4 deletions internal/test_helpers/fixtures/fs_isolation/success
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
Debug = true

[stage-4] Running tests for Stage #4: fs_isolation
[stage-4] Running tests for Stage #4: if6
[stage-4] Created temp dir on host: /tmp/88398
[stage-4] Executing: ./your_docker.sh run <some_image> /usr/local/bin/docker-explorer ls /tmp/88398
[stage-4] (expecting that the directory won't be accessible)
[your_program] No such file or directory
[stage-4] Test passed.

[stage-3] Running tests for Stage #3: exit_code
[stage-3] Running tests for Stage #3: cn8
[stage-3] Executing: ./your_docker.sh run <some_image> /usr/local/bin/docker-explorer exit 3
[stage-3] Checking the parent process's exit code..
[stage-3] Test passed.

[stage-2] Running tests for Stage #2: stdio
[stage-2] Running tests for Stage #2: kf3
[stage-2] Executing: ./your_docker.sh run <some_image> /usr/local/bin/docker-explorer echo 88398
[your_program] 88398
[stage-2] Checking if the string was echo-ed to stdout..
Expand All @@ -21,7 +21,7 @@ Debug = true
[stage-2] Checking if the string was echo-ed to stderr..
[stage-2] Test passed.

[stage-1] Running tests for Stage #1: init
[stage-1] Running tests for Stage #1: je9
[stage-1] Executing: ./your_docker.sh run <some_image> /usr/local/bin/docker-explorer echo 88398
[your_program] 88398
[stage-1] Checking if the command output was echo-ed..
Expand Down
10 changes: 5 additions & 5 deletions internal/test_helpers/fixtures/process_isolation/success
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
Debug = true

[stage-5] Running tests for Stage #5: process_isolation
[stage-5] Running tests for Stage #5: lu7
[stage-5] Executing: ./your_docker.sh run <some_image> /usr/local/bin/docker-explorer mypid
[your_program] 1
[stage-5] Test passed.

[stage-4] Running tests for Stage #4: fs_isolation
[stage-4] Running tests for Stage #4: if6
[stage-4] Created temp dir on host: /tmp/88398
[stage-4] Executing: ./your_docker.sh run <some_image> /usr/local/bin/docker-explorer ls /tmp/88398
[stage-4] (expecting that the directory won't be accessible)
[your_program] No such file or directory
[stage-4] Test passed.

[stage-3] Running tests for Stage #3: exit_code
[stage-3] Running tests for Stage #3: cn8
[stage-3] Executing: ./your_docker.sh run <some_image> /usr/local/bin/docker-explorer exit 3
[stage-3] Checking the parent process's exit code..
[stage-3] Test passed.

[stage-2] Running tests for Stage #2: stdio
[stage-2] Running tests for Stage #2: kf3
[stage-2] Executing: ./your_docker.sh run <some_image> /usr/local/bin/docker-explorer echo 88398
[your_program] 88398
[stage-2] Checking if the string was echo-ed to stdout..
Expand All @@ -26,7 +26,7 @@ Debug = true
[stage-2] Checking if the string was echo-ed to stderr..
[stage-2] Test passed.

[stage-1] Running tests for Stage #1: init
[stage-1] Running tests for Stage #1: je9
[stage-1] Executing: ./your_docker.sh run <some_image> /usr/local/bin/docker-explorer echo 88398
[your_program] 88398
[stage-1] Checking if the command output was echo-ed..
Expand Down
2 changes: 1 addition & 1 deletion internal/test_helpers/fixtures/stdio/failure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Debug = true

[stage-2] Running tests for Stage #2: stdio
[stage-2] Running tests for Stage #2: kf3
[stage-2] Executing: ./your_docker.sh run <some_image> /usr/local/bin/docker-explorer echo 88398
[your_program] 88398
[stage-2] Checking if the string was echo-ed to stdout..
Expand Down
4 changes: 2 additions & 2 deletions internal/test_helpers/fixtures/stdio/success
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Debug = true

[stage-2] Running tests for Stage #2: stdio
[stage-2] Running tests for Stage #2: kf3
[stage-2] Executing: ./your_docker.sh run <some_image> /usr/local/bin/docker-explorer echo 88398
[your_program] 88398
[stage-2] Checking if the string was echo-ed to stdout..
Expand All @@ -9,7 +9,7 @@ Debug = true
[stage-2] Checking if the string was echo-ed to stderr..
[stage-2] Test passed.

[stage-1] Running tests for Stage #1: init
[stage-1] Running tests for Stage #1: je9
[stage-1] Executing: ./your_docker.sh run <some_image> /usr/local/bin/docker-explorer echo 88398
[your_program] 88398
[stage-1] Checking if the command output was echo-ed..
Expand Down

0 comments on commit 41031a6

Please sign in to comment.