Use stdout2env in PR acceptance tests

This commit is contained in:
William Martin 2024-10-08 15:12:13 +02:00
parent 37171628c6
commit 464a69ae87
3 changed files with 17 additions and 6 deletions

View file

@ -58,11 +58,20 @@ var sharedSetup = func(ts *testscript.Env) error {
var sharedCmds = map[string]func(ts *testscript.TestScript, neg bool, args []string){
"defer": func(ts *testscript.TestScript, neg bool, args []string) {
ts.Defer(func() {
if err := ts.Exec(args[0], args[1:]...); err != nil {
ts.Fatalf("deferred command failed: %v", err)
}
ts.Check(ts.Exec(args[0], args[1:]...))
})
}}
},
"stdout2env": func(ts *testscript.TestScript, neg bool, args []string) {
if neg {
ts.Fatalf("unsupported: ! stdout2env")
}
if len(args) != 1 {
ts.Fatalf("usage: stdout2env name")
}
ts.Setenv(args[0], strings.TrimRight(ts.ReadFile("stdout"), "\n"))
},
}
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

View file

@ -18,6 +18,7 @@ exec git push -u origin feature-branch
# Create the PR
exec gh pr create --title 'Feature Title' --body 'Feature Body'
stdout2env PR_URL
# Remove the local branch
exec git checkout main
@ -25,5 +26,5 @@ exec git branch -D feature-branch
stdout 'Deleted branch feature-branch'
# Checkout the PR
exec gh pr checkout 1
exec gh pr checkout $PR_URL
stderr 'Switched to a new branch ''feature-branch'''

View file

@ -18,7 +18,8 @@ exec git push -u origin feature-branch
# Create the PR
exec gh pr create --title 'Feature Title' --body 'Feature Body'
stdout2env PR_URL
# View the PR
exec gh pr view 1
exec gh pr view $PR_URL
stdout 'Feature Title'