From 15d1eca41ed40fd77c5b3a9108232ca73bd27347 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Sat, 24 Apr 2021 18:57:55 +0200 Subject: [PATCH] Add tests for AWS ecr Signed-off-by: Tom Chauveau --- stdlib/aws/ecr/ecr.cue | 4 +- tests/stdlib.bats | 7 +++ tests/stdlib/aws/ecr/ecr.cue | 98 ++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 tests/stdlib/aws/ecr/ecr.cue diff --git a/stdlib/aws/ecr/ecr.cue b/stdlib/aws/ecr/ecr.cue index 75b7de36..71bdc545 100644 --- a/stdlib/aws/ecr/ecr.cue +++ b/stdlib/aws/ecr/ecr.cue @@ -14,7 +14,9 @@ import ( // ECR credentials username: "AWS" - secret: out + // FIXME Exected twice and trigger error : "TestECR.creds.secret: 2 errors in empty disjunction" + // Happend because of v0.8.3 of buildkit container + secret: out aws.#Script & { always: true diff --git a/tests/stdlib.bats b/tests/stdlib.bats index 0da60c0a..88c159d4 100644 --- a/tests/stdlib.bats +++ b/tests/stdlib.bats @@ -43,8 +43,15 @@ setup() { "$DAGGER" compute "$TESTDIR"/stdlib/aws/s3 --input-dir TestDirectory="$TESTDIR"/stdlib/aws/s3/testdata --input-yaml "$TESTDIR"/stdlib/aws/inputs.yaml } + @test "stdlib: aws" { skip_unless_secrets_available "$TESTDIR"/stdlib/aws/inputs.yaml "$DAGGER" compute "$TESTDIR"/stdlib/aws/eks --input-yaml "$TESTDIR"/stdlib/aws/inputs.yaml +} + +@test "stdlib: ecr" { + skip_unless_secrets_available "$TESTDIR"/stdlib/aws/inputs.yaml + + "$DAGGER" compute "$TESTDIR"/stdlib/aws/ecr --input-yaml "$TESTDIR"/stdlib/aws/inputs.yaml } \ No newline at end of file diff --git a/tests/stdlib/aws/ecr/ecr.cue b/tests/stdlib/aws/ecr/ecr.cue new file mode 100644 index 00000000..0399c080 --- /dev/null +++ b/tests/stdlib/aws/ecr/ecr.cue @@ -0,0 +1,98 @@ +package ecr + +import ( + "dagger.io/aws" + "dagger.io/aws/ecr" + "dagger.io/alpine" + "dagger.io/dagger/op" +) + +TestConfig: awsConfig: aws.#Config & { + region: "us-east-2" +} + +// Generate a random number +random: { + string + #up: [ + op.#Load & {from: alpine.#Image}, + op.#Exec & { + args: ["sh", "-c", "cat /dev/urandom | tr -dc 'a-z' | fold -w 10 | head -n 1 | tr -d '\n' > /rand"] + }, + op.#Export & { + source: "/rand" + }, + ] +} + +TestECR: { + repository: "125635003186.dkr.ecr.\(TestConfig.awsConfig.region).amazonaws.com/dagger-ci" + tag: "test-ecr-\(random)" + + creds: ecr.#Credentials & { + config: TestConfig.awsConfig + } + + push: { + ref: "\(repository):\(tag)" + + #up: [ + op.#DockerBuild & { + dockerfile: """ + FROM alpine + RUN echo \(random) > /test + """ + }, + + op.#DockerLogin & { + target: repository + username: creds.username + secret: creds.secret + }, + + op.#PushContainer & { + "ref": ref + }, + ] + } + + pull: #up: [ + op.#DockerLogin & { + target: push.ref + username: creds.username + secret: creds.secret + }, + + op.#FetchContainer & { + ref: push.ref + }, + ] + + verify: #up: [ + op.#Load & { + from: pull + }, + + op.#Exec & { + always: true + args: [ + "sh", "-c", "test $(cat test) = \(random)", + ] + }, + ] + + verifyBuild: #up: [ + op.#DockerLogin & { + target: push.ref + username: creds.username + secret: creds.secret + }, + + op.#DockerBuild & { + dockerfile: #""" + FROM \#(push.ref) + RUN test $(cat test) = \#(random) + """# + }, + ] +}