diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a27db0d..0a4d0bd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,16 +43,3 @@ jobs: echo "gofmt failed, please run gofmt -w ." exit 1 fi - - integration: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: 1.21 - - - name: Run integration tests - run: tests/local diff --git a/testdata/scripts/local.txt b/testdata/scripts/local.txt new file mode 100644 index 0000000..220f68f --- /dev/null +++ b/testdata/scripts/local.txt @@ -0,0 +1,17 @@ +# Normal usage clones dependabot-fixtures/go-modules-lib +dependabot update go_modules dependabot-fixtures/go-modules-lib --cache cache +stderr 'https://github.com:443/dependabot-fixtures/go-modules-lib/git-upload-pack' +stdout 'create_pull_request' + +exec git clone https://github.com/dependabot-fixtures/go-modules-lib repo + +# Using --local prevents cloning +dependabot update go_modules dependabot-fixtures/go-modules-lib --local repo --cache cache +! stderr 'https://github.com:443/dependabot-fixtures/go-modules-lib/git-upload-pack' +stdout 'create_pull_request' + +# Verify it works with a non-git repo +rm -rf tmp/sys/.git +dependabot update go_modules dependabot-fixtures/go-modules-lib --local repo --cache cache +! stderr 'https://github.com:443/dependabot-fixtures/go-modules-lib/git-upload-pack' +stdout 'create_pull_request' diff --git a/tests/dependabot_test.go b/tests/dependabot_test.go index 632d0d0..5d6aab0 100644 --- a/tests/dependabot_test.go +++ b/tests/dependabot_test.go @@ -8,6 +8,7 @@ import ( "os/exec" "rsc.io/script" "rsc.io/script/scripttest" + "sync" "testing" ) @@ -39,7 +40,7 @@ func Commands() map[string]script.Cmd { return commands } -// Dependabot runs the Dependabot CLI. TODO Should this build once then execute thereafter? +// Dependabot runs the Dependabot CLI. func Dependabot() script.Cmd { return script.Command( script.CmdUsage{ @@ -51,10 +52,21 @@ func Dependabot() script.Cmd { return nil, script.ErrUsage } - args = append([]string{"run", "../cmd/dependabot/dependabot.go"}, args...) - execCmd := exec.Command("go", args...) + sync.OnceFunc(func() { + err := exec.Command("go", "build", "../cmd/dependabot/dependabot.go").Run() + if err != nil { + panic("failed to build dependabot") + } + if err := os.Rename("dependabot", s.Getwd()+"/dependabot"); err != nil { + panic("failed to move dependabot into test directory") + } + })() + + execCmd := exec.Command("./dependabot", args...) var execOut, execErr bytes.Buffer + execCmd.Dir = s.Getwd() + execCmd.Env = s.Environ() execCmd.Stdout = &execOut execCmd.Stderr = &execErr diff --git a/tests/local b/tests/local deleted file mode 100755 index 0642d1b..0000000 --- a/tests/local +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -go build cmd/dependabot/dependabot.go - -# To get a clear signal we're not cloning, using a repo with no dependencies. -git clone https://github.com/golang/sys tmp/sys -trap 'rm -rf tmp/sys' EXIT - -./dependabot update go_modules golang/sys --local tmp/sys 2>&1 | tee tmp/output - -# verify the repo was not cloned -if grep -q "https://github.com:443/golang/sys/git-upload-pack" tmp/output; then - echo "FAIL: repo was cloned" - export FAIL=1 -fi - -# Next, test using a repo that isn't a Git repository. -rm -rf tmp/sys/.git - -./dependabot update go_modules golang/sys --local tmp/sys 2>&1 | tee tmp/output - -# verify the repo was not cloned -if grep -q "https://github.com:443/golang/sys/git-upload-pack" tmp/output; then - echo "FAIL: repo was cloned" - export FAIL=1 -fi - -if [ -n "${FAIL:-}" ]; then - exit 1 -fi