From 43b9df74a862fefeeea7acf32a2fdf7fea68a3b3 Mon Sep 17 00:00:00 2001 From: Joel Longtine Date: Thu, 10 Mar 2022 15:15:50 -0700 Subject: [PATCH] Add test Signed-off-by: Joel Longtine --- cmd/dagger/cmd/do.go | 8 ++- tests/plan.bats | 5 ++ .../do/error_message_for_0.1_projects.cue | 60 +++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 tests/plan/do/error_message_for_0.1_projects.cue diff --git a/cmd/dagger/cmd/do.go b/cmd/dagger/cmd/do.go index d53504ee..e137f661 100644 --- a/cmd/dagger/cmd/do.go +++ b/cmd/dagger/cmd/do.go @@ -130,7 +130,13 @@ func doHelp(cmd *cobra.Command, _ []string) { p, err := loadPlan() if err != nil { - errorMsg = "Error: failed to load plan\n\n" + errstring := err.Error() + if strings.Contains(errstring, "cannot find package") && strings.Contains(errstring, "alpha.dagger.io") { + errorMsg = "Attempting to load a dagger 0.1.0 project. Please upgrade your config to be compatible with this version of dagger. Contact the Dagger team if you need help!\n\n" + // lg.Fatal().Msg("Attempting to load a dagger 0.1.0 project. Please upgrade your config to be compatible with this version of dagger. Contact the Dagger team if you need help!") + } else { + errorMsg = "Error: failed to load plan\n\n" + } } else { loadedMsg = "Plan loaded from " + planPath actionLookupPath := getTargetPath(cmd.Flags().Args()) diff --git a/tests/plan.bats b/tests/plan.bats index 2d6b4866..30432aee 100644 --- a/tests/plan.bats +++ b/tests/plan.bats @@ -38,6 +38,11 @@ setup() { refute_output --partial 'client.filesystem."./dependent_do".write' } +@test "plan/do: Nice error message for 0.1.0 projects" { + run "$DAGGER" "do" -p ./plan/do/error_message_for_0.1_projects.cue + assert_output --partial "Attempting to load a 0.1.0 plan." +} + @test "plan/hello" { # Europa loader handles the cwd differently, therefore we need to CD into the tree at or below the parent of cue.mod cd "$TESTDIR" diff --git a/tests/plan/do/error_message_for_0.1_projects.cue b/tests/plan/do/error_message_for_0.1_projects.cue new file mode 100644 index 00000000..4cd6b10e --- /dev/null +++ b/tests/plan/do/error_message_for_0.1_projects.cue @@ -0,0 +1,60 @@ +package main + +import ( + "alpha.dagger.io/dagger" + "alpha.dagger.io/aws/s3" + "alpha.dagger.io/netlify" + "alpha.dagger.io/os" +) + +repo: dagger.#Artifact & dagger.#Input + +hello: { + + dir: dagger.#Artifact & dagger.#Input + + ctr: os.#Container & { + command: """ + ls -l /src > /tmp/out + """ + mount: "/src": from: dir + } + + f: os.#File & { + from: ctr + path: "/tmp/out" + } + + message: f.contents & dagger.#Output +} + +// Website +web: { + source: os.#Dir & { + from: repo + path: "web" + } + + url: string & dagger.#Output + + // Where to host the website? + provider: *"s3" | "netlify" & dagger.#Input + + // Deploy to AWS S3 + if provider == "s3" { + url: "\(bucket.url)index.html" + bucket: s3.#Put & { + contentType: "text/html" + "source": source + } + } + + // Deploy to Netlify + if provider == "netlify" { + url: site.url + + site: netlify.#Site & { + contents: source + } + } +}