From 8ff72a5fa3a9d4bc99be411ca1b74a80649781f7 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Fri, 21 Jan 2022 12:45:59 -0800 Subject: [PATCH] test: clean up yarn test Signed-off-by: Andrea Luzzardi --- pkg/dagger.io/dagger/utils.cue | 6 +++ .../yarn/test/yarn-test.cue | 48 ++++++++----------- plan/task/exec.go | 7 ++- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/pkg/dagger.io/dagger/utils.cue b/pkg/dagger.io/dagger/utils.cue index b06dba22..43e64f67 100644 --- a/pkg/dagger.io/dagger/utils.cue +++ b/pkg/dagger.io/dagger/utils.cue @@ -8,6 +8,12 @@ import ( // This may safely be called from any package #Source: engine.#Source +// A (best effort) persistent cache dir +#CacheDir: engine.#CacheDir + +// A temporary directory for command execution +#TempDir: engine.#TempDir + // Select a subdirectory from a filesystem tree #Subdir: { // Input tree diff --git a/pkg/universe.dagger.io/yarn/test/yarn-test.cue b/pkg/universe.dagger.io/yarn/test/yarn-test.cue index 46262d6a..d35d535f 100644 --- a/pkg/universe.dagger.io/yarn/test/yarn-test.cue +++ b/pkg/universe.dagger.io/yarn/test/yarn-test.cue @@ -2,11 +2,9 @@ package yarn import ( "dagger.io/dagger" - "dagger.io/dagger/engine" - "universe.dagger.io/yarn" - // "universe.dagger.io/alpine" - // "universe.dagger.io/bash" + "universe.dagger.io/alpine" + "universe.dagger.io/bash" ) dagger.#Plan & { @@ -16,34 +14,28 @@ dagger.#Plan & { } actions: { - TestReact: { - cache: engine.#CacheDir & { - id: "yarn cache" - } + cache: dagger.#CacheDir & { + id: "yarn cache" + } - pkg: yarn.#Build & { - source: inputs.directories.testdata.contents - "cache": cache - } + pkg: yarn.#Build & { + source: inputs.directories.testdata.contents + "cache": cache + } - _image: engine.#Pull & { - source: "alpine:3.15.0@sha256:e7d88de73db3d3fd9b2d63aa7f447a10fd0220b7cbf39803c803f2af9ba256b3" - } + _image: alpine.#Build & { + packages: bash: {} + } - // FIXME: use bash.#Script - test: engine.#Exec & { - input: _image.output - mounts: build: { - dest: "/build" - contents: pkg.output - } - args: [ - "sh", "-c", - #""" - test "$(cat /build/test)" = "output" - """#, - ] + test: bash.#Run & { + image: _image.output + mounts: build: { + dest: "/build" + contents: pkg.output } + script: #""" + test "$(cat /build/test)" = "output" + """# } // FIXME: re-enable? diff --git a/plan/task/exec.go b/plan/task/exec.go index e6fe7d3a..2462d6f8 100644 --- a/plan/task/exec.go +++ b/plan/task/exec.go @@ -190,7 +190,12 @@ func (t *execTask) mountTmp(_ *plancontext.Context, dest string, _ *compiler.Val func (t *execTask) mountCache(_ *plancontext.Context, dest string, mnt *compiler.Value) (llb.RunOption, error) { contents := mnt.Lookup("contents") - id, err := contents.Lookup("id").String() + + idValue := contents.Lookup("id") + if !idValue.IsConcrete() { + return nil, fmt.Errorf("cache %q is not set", mnt.Path().String()) + } + id, err := idValue.String() if err != nil { return nil, err }