Merge pull request #175 from dagger/test-push

test: PushContainer
This commit is contained in:
Andrea Luzzardi
2021-03-12 18:12:01 -08:00
committed by GitHub
6 changed files with 100 additions and 10 deletions

View File

@@ -0,0 +1,56 @@
package main
import (
"dagger.io/dagger"
"dagger.io/alpine"
)
TestPushContainer: {
// Generate a random number
random: {
string
#compute: [
dagger.#Load & {from: alpine.#Image},
dagger.#Exec & {
args: ["sh", "-c", "echo -n $RANDOM > /rand"]
},
dagger.#Export & {
source: "/rand"
},
]
}
// Push an image with a random tag
push: {
ref: "daggerio/ci-test:\(random)"
#compute: [
dagger.#WriteFile & {
content: random
dest: "/rand"
},
dagger.#PushContainer & {
"ref": ref
},
]
}
// Pull the image back
pull: #compute: [
dagger.#FetchContainer & {
ref: push.ref
},
]
// Check the content
check: #compute: [
dagger.#Load & {from: alpine.#Image},
dagger.#Exec & {
args: [
"sh", "-c", #"""
test "$(cat /src/rand)" = "\#(random)"
"""#,
]
mount: "/src": from: pull
},
]
}

View File

@@ -130,3 +130,11 @@ test::one(){
disable(){
logger::warning "Test \"$2\" has been disabled."
}
secret(){
if [ -z "${DAGGER_SECRETS_LOADED+x}" ] || [ "$DAGGER_SECRETS_LOADED" != "1" ]; then
logger::warning "Skip \"$2\": secrets not available"
else
"$@"
fi
}

BIN
tests/test.secret Normal file

Binary file not shown.

View File

@@ -6,6 +6,11 @@ readonly d=$(cd "$(dirname "${BASH_SOURCE[0]:-$PWD}")" 2>/dev/null 1>&2 && pwd)
# shellcheck source=/dev/null
. "$d/test-lib.sh"
# shellcheck source=/dev/null
if grep -q "DAGGER_SECRETS" "$d/test.secret"; then
source "$d/test.secret"
fi
# Point this to your dagger binary
readonly DAGGER_BINARY="${DAGGER_BINARY:-$d/../cmd/dagger/dagger}"
# The default arguments are a no-op, but having "anything" is a little cheat necessary for "${DAGGER_BINARY_ARGS[@]}" to not be empty down there
@@ -79,6 +84,13 @@ test::fetchcontainer(){
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/fetch-container/nonexistent/image-with-valid-digest
}
test::pushcontainer(){
local dagger="$1"
secret test::one "PushContainer: simple" --exit=0 \
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/push-container
}
test::fetchgit(){
local dagger="$1"
@@ -194,7 +206,6 @@ test::local(){
disable "" "There are no local tests right now (the feature is possibly not functioning at all: see https://github.com/blocklayerhq/dagger/issues/41)"
}
test::mount(){
test::one "Mount: tmpfs" --exit=0 \
"$dagger" "${DAGGER_BINARY_ARGS[@]}" compute "$d"/mounts/valid/tmpfs
@@ -244,6 +255,7 @@ test::all(){
test::local "$dagger"
test::compute "$dagger"
test::fetchcontainer "$dagger"
test::pushcontainer "$dagger"
test::fetchgit "$dagger"
test::exec "$dagger"
test::export "$dagger"