Add tests on docker.#Build
definition
- Simple build test - Multi step to build a go binary Signed-off-by: Vasek - Tom C <tom.chauveau@epitech.eu>
This commit is contained in:
parent
c2a7766293
commit
26b2ef8697
49
pkg/universe.dagger.io/docker/test/build-multi-steps.cue
Normal file
49
pkg/universe.dagger.io/docker/test/build-multi-steps.cue
Normal file
@ -0,0 +1,49 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/dagger/engine"
|
||||
"universe.dagger.io/docker"
|
||||
)
|
||||
|
||||
// This test verify that we can correctly build an image
|
||||
// using docker.#Build with multiple steps executed during
|
||||
// the building process
|
||||
dagger.#Plan & {
|
||||
inputs: directories: testdata: path: "./testdata"
|
||||
|
||||
actions: {
|
||||
image: docker.#Build & {
|
||||
steps: [
|
||||
docker.#Pull & {
|
||||
source: "golang:1.17-alpine"
|
||||
},
|
||||
docker.#Copy & {
|
||||
contents: inputs.directories.testdata.contents
|
||||
dest: "/input"
|
||||
},
|
||||
docker.#Run & {
|
||||
script: """
|
||||
# FIXME remove that line when #1517 is merged
|
||||
export PATH=/go/bin:/usr/local/go/bin:$PATH
|
||||
go build -o hello ./main.go
|
||||
mv hello /bin
|
||||
"""
|
||||
workdir: "/input"
|
||||
},
|
||||
docker.#Run & {
|
||||
script: """
|
||||
hello >> /test.txt
|
||||
"""
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
verify: engine.#ReadFile & {
|
||||
input: image.output.rootfs
|
||||
path: "/test.txt"
|
||||
} & {
|
||||
contents: "hello world"
|
||||
}
|
||||
}
|
||||
}
|
38
pkg/universe.dagger.io/docker/test/build-simple.cue
Normal file
38
pkg/universe.dagger.io/docker/test/build-simple.cue
Normal file
@ -0,0 +1,38 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"dagger.io/dagger"
|
||||
"dagger.io/dagger/engine"
|
||||
"universe.dagger.io/docker"
|
||||
)
|
||||
|
||||
// This test verify that we can correctly build a simplistic image
|
||||
// using docker.#Build
|
||||
dagger.#Plan & {
|
||||
#alpineImage: "index.docker.io/alpine:3.15.0@sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300"
|
||||
|
||||
#testValue: "hello world"
|
||||
|
||||
actions: {
|
||||
image: docker.#Build & {
|
||||
steps: [
|
||||
docker.#Pull & {
|
||||
source: #alpineImage
|
||||
},
|
||||
docker.#Run & {
|
||||
script: """
|
||||
echo -n $TEST >> /test.txt
|
||||
"""
|
||||
env: TEST: #testValue
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
verify: engine.#ReadFile & {
|
||||
input: image.output.rootfs
|
||||
path: "/test.txt"
|
||||
} & {
|
||||
contents: #testValue
|
||||
}
|
||||
}
|
||||
}
|
@ -5,6 +5,9 @@ setup() {
|
||||
}
|
||||
|
||||
@test "docker.#Build" {
|
||||
dagger up ./build-simple.cue
|
||||
dagger up ./build-multi-steps.cue
|
||||
|
||||
dagger up ./nested-build-test.cue
|
||||
|
||||
# FIXME: this is currently broken
|
||||
|
3
pkg/universe.dagger.io/docker/test/testdata/go.mod
vendored
Normal file
3
pkg/universe.dagger.io/docker/test/testdata/go.mod
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
module test.com
|
||||
|
||||
go 1.17
|
7
pkg/universe.dagger.io/docker/test/testdata/main.go
vendored
Normal file
7
pkg/universe.dagger.io/docker/test/testdata/main.go
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Printf("hello world")
|
||||
}
|
Reference in New Issue
Block a user