Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Golang localtests #1203

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add collapsible stdout
timvaillancourt committed Dec 4, 2022
commit 34646f553d8f248d6885ed082cc74822e164f680
18 changes: 16 additions & 2 deletions go/localtests/test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package localtests

import (
"bufio"
"bytes"
"database/sql"
"fmt"
"io"
"log"
"os"
"os/exec"
"strings"
)

// Test represents a single test.
@@ -126,12 +130,22 @@ func (test *Test) Migrate(config Config, primary, replica *sql.DB) (err error) {
cmd.Stderr = &stderr
cmd.Stdout = &output

if strings.TrimSpace(os.Getenv("GITHUB_ACTION")) == "true" {
go func(reader io.Reader) {
scanner := bufio.NewScanner(output)
fmt.Printf("::group::%s stdout\n", test.Name)
for scanner.Scan() {
fmt.Println(scanner.Text())
}
fmt.Println("::endgroup::")
}(&output)
}

if err = cmd.Run(); err != nil {
if isExpectedFailureOutput(&stderr, test.ExpectedFailure) {
return nil
}
output.Write(stderr.Bytes())
log.Printf("[%s] test failed: %+v", test.Name, output.String())
log.Printf("[%s] test failed: %+v", test.Name, stderr.String())
}
return err
}