Add test for docker example

Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
Tom Chauveau 2021-05-06 22:27:45 +02:00
parent a79f10a9bb
commit 24aee99ba9
10 changed files with 124 additions and 1 deletions

View File

@ -9,6 +9,6 @@ import (
source: dagger.#Artifact
// Container image
container: docker.#ImageFromSource & {
container: docker.#Build & {
"source": source
}

View File

@ -18,3 +18,11 @@ setup() {
assert_success
assert_output --partial "Todo App"
}
@test "example: docker" {
skip_unless_file_exist "$TESTDIR"/examples/docker/Dockerfile
"$DAGGER" new --plan-dir "$TESTDIR"/../examples/docker/ docker
"$DAGGER" input dir source "$TESTDIR"/examples/docker/ -e "docker"
"$DAGGER" up -e "docker"
}

View File

@ -0,0 +1,2 @@
FROM alpine
RUN echo test >> /test.txt

View File

@ -19,6 +19,11 @@ skip_unless_secrets_available() {
sops exec-file "$inputFile" echo > /dev/null 2>&1 || skip "$inputFile cannot be decrypted"
}
skip_unless_file_exist() {
local inputFile="$1"
test -f "$inputFile" || skip "$inputFile does not exist"
}
skip_unless_local_kube() {
if [ -f ~/.kube/config ] && grep -q "user: kind-kind" ~/.kube/config &> /dev/null && grep -q "127.0.0.1" ~/.kube/config &> /dev/null; then
echo "Kubernetes available"

View File

@ -60,6 +60,19 @@ setup() {
"$DAGGER" compute "$TESTDIR"/stdlib/aws/ecr --input-yaml "$TESTDIR"/stdlib/aws/inputs.yaml
}
@test "stdlib: docker-build" {
skip_unless_file_exist "$TESTDIR"/stdlib/docker/build/Dockerfile
"$DAGGER" compute "$TESTDIR"/stdlib/docker/build/ --input-dir source="$TESTDIR"/stdlib/docker/build
}
@test "stdlib: docker-pull" {
"$DAGGER" compute "$TESTDIR"/stdlib/docker/pull/
}
@test "stdlib: docker-dockerfile" {
"$DAGGER" compute "$TESTDIR"/stdlib/docker/dockerfile/ --input-dir source="$TESTDIR"/stdlib/docker/dockerfile/testdata
}
@test "stdlib: terraform" {
skip_unless_secrets_available "$TESTDIR"/stdlib/aws/inputs.yaml

View File

@ -0,0 +1,2 @@
FROM alpine
RUN echo test >> /test.txt

View File

@ -0,0 +1,31 @@
package docker
import (
"dagger.io/dagger"
"dagger.io/dagger/op"
"dagger.io/docker"
)
// Build a Docker image from source, using included Dockerfile
source: dagger.#Artifact
TestBuild: {
image: docker.#Build & {
"source": source
}
verify: #up: [
op.#Load & {
from: image
},
op.#Exec & {
always: true
args: [
"sh", "-c", """
grep -q "test" /test.txt
""",
]
},
]
}

View File

@ -0,0 +1,34 @@
package docker
import (
"dagger.io/dagger"
"dagger.io/dagger/op"
"dagger.io/docker"
)
source: dagger.#Artifact
TestImageFromDockerfile: {
image: docker.#ImageFromDockerfile & {
dockerfile: """
FROM alpine
COPY test.txt /test.txt
"""
context: source
}
verify: #up: [
op.#Load & {
from: image
},
op.#Exec & {
always: true
args: [
"sh", "-c", """
grep -q "test" /test.txt
""",
]
},
]
}

View File

@ -0,0 +1 @@
test

View File

@ -0,0 +1,27 @@
package docker
import (
"dagger.io/dagger/op"
"dagger.io/docker"
)
TestImageFromRegistry: {
image: docker.#Pull & {
from: "index.docker.io/the0only0vasek/alpine-test"
}
verify: #up: [
op.#Load & {
from: image
},
op.#Exec & {
always: true
args: [
"sh", "-c", """
grep -q "test" /test.txt
""",
]
},
]
}