From 8c44f9d39733eb7719264ccc51d3b769f86df538 Mon Sep 17 00:00:00 2001 From: Jake Coffman Date: Fri, 22 Dec 2023 06:45:52 -0600 Subject: [PATCH] add more tests --- cmd/dependabot/internal/cmd/update.go | 4 ++++ testdata/scripts/basic.txt | 2 ++ testdata/scripts/input.txt | 5 +++++ testdata/scripts/local.txt | 2 ++ testdata/scripts/timeout.txt | 24 ++++++++++++++++++++++++ 5 files changed, 37 insertions(+) create mode 100644 testdata/scripts/timeout.txt diff --git a/cmd/dependabot/internal/cmd/update.go b/cmd/dependabot/internal/cmd/update.go index 9aa9b09..ed0200a 100644 --- a/cmd/dependabot/internal/cmd/update.go +++ b/cmd/dependabot/internal/cmd/update.go @@ -2,6 +2,7 @@ package cmd import ( "bytes" + "context" "encoding/json" "errors" "fmt" @@ -91,6 +92,9 @@ func NewUpdateCommand() *cobra.Command { Writer: writer, ApiUrl: flags.apiUrl, }); err != nil { + if errors.Is(err, context.DeadlineExceeded) { + log.Fatalf("update timed out after %s", flags.timeout) + } log.Fatalf("failed to run updater: %v", err) } diff --git a/testdata/scripts/basic.txt b/testdata/scripts/basic.txt index c248722..5bf82ce 100644 --- a/testdata/scripts/basic.txt +++ b/testdata/scripts/basic.txt @@ -8,6 +8,8 @@ dependabot update go_modules dependabot/cli --updater-image dummy-updater stderr 'bin/run arguments: fetch_files' stderr 'bin/run arguments: update_files' +exec docker rmi -f dummy-updater + -- Dockerfile -- FROM ubuntu:22.04 diff --git a/testdata/scripts/input.txt b/testdata/scripts/input.txt index 4b59be9..0e7c620 100644 --- a/testdata/scripts/input.txt +++ b/testdata/scripts/input.txt @@ -18,6 +18,11 @@ stderr 'commit must be a SHA, or not provided' dependabot update go_modules dependabot/cli --dep golang.org/x/image --updater-image input-verify-updater stderr '"allowed-updates":\[\{"dependency-name":"golang.org/x/image"\}\]' +dependabot update go_modules dependabot/cli --directory /code --updater-image input-verify-updater +stderr '"directory":"\/code"' + +exec docker rmi -f input-verify-updater + -- Dockerfile -- FROM ubuntu:22.04 diff --git a/testdata/scripts/local.txt b/testdata/scripts/local.txt index ffcb23d..1e3fc0f 100644 --- a/testdata/scripts/local.txt +++ b/testdata/scripts/local.txt @@ -11,6 +11,8 @@ dependabot update go_modules dependabot-fixtures/go-modules-lib --updater-image stderr \.git stderr hello.txt +exec docker rmi -f local-updater + -- Dockerfile -- FROM ubuntu:22.04 diff --git a/testdata/scripts/timeout.txt b/testdata/scripts/timeout.txt new file mode 100644 index 0000000..7d501ca --- /dev/null +++ b/testdata/scripts/timeout.txt @@ -0,0 +1,24 @@ +exec docker build -t sleepy-updater . + +! dependabot update go_modules dependabot/cli --timeout 1s --updater-image sleepy-updater +stderr 'update timed out after 1s' + +exec docker rmi -f sleepy-updater + +-- Dockerfile -- +FROM ubuntu:22.04 + +RUN useradd dependabot + +COPY --chown=dependabot --chmod=755 update-ca-certificates /usr/bin/update-ca-certificates +COPY --chown=dependabot --chmod=755 run bin/run + +-- update-ca-certificates -- +#!/usr/bin/env bash + +echo "Updated those certificates for ya" + +-- run -- +#!/usr/bin/env bash + +sleep 10