Skip to content

Commit

Permalink
convert old script test to new script test
Browse files Browse the repository at this point in the history
  • Loading branch information
jakecoffman committed Dec 21, 2023
1 parent 97066f1 commit 034be58
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 48 deletions.
13 changes: 0 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions testdata/scripts/local.txt
Original file line number Diff line number Diff line change
@@ -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'
18 changes: 15 additions & 3 deletions tests/dependabot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os/exec"
"rsc.io/script"
"rsc.io/script/scripttest"
"sync"
"testing"
)

Expand Down Expand Up @@ -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{
Expand All @@ -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

Expand Down
32 changes: 0 additions & 32 deletions tests/local

This file was deleted.

0 comments on commit 034be58

Please sign in to comment.