This removes sensitivity to the BROWSER environment variable in tests and makes it easier to verify the URL that the browser was invoked with without having to stub sub-processes.
59 lines
1,004 B
Go
59 lines
1,004 B
Go
package test
|
|
|
|
import (
|
|
"bytes"
|
|
"regexp"
|
|
)
|
|
|
|
// TODO copypasta from command package
|
|
type CmdOut struct {
|
|
OutBuf *bytes.Buffer
|
|
ErrBuf *bytes.Buffer
|
|
BrowsedURL string
|
|
}
|
|
|
|
func (c CmdOut) String() string {
|
|
return c.OutBuf.String()
|
|
}
|
|
|
|
func (c CmdOut) Stderr() string {
|
|
return c.ErrBuf.String()
|
|
}
|
|
|
|
// OutputStub implements a simple utils.Runnable
|
|
type OutputStub struct {
|
|
Out []byte
|
|
Error error
|
|
}
|
|
|
|
func (s OutputStub) Output() ([]byte, error) {
|
|
if s.Error != nil {
|
|
return s.Out, s.Error
|
|
}
|
|
return s.Out, nil
|
|
}
|
|
|
|
func (s OutputStub) Run() error {
|
|
if s.Error != nil {
|
|
return s.Error
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type T interface {
|
|
Helper()
|
|
Errorf(string, ...interface{})
|
|
}
|
|
|
|
// Deprecated: prefer exact matches for command output
|
|
func ExpectLines(t T, output string, lines ...string) {
|
|
t.Helper()
|
|
var r *regexp.Regexp
|
|
for _, l := range lines {
|
|
r = regexp.MustCompile(l)
|
|
if !r.MatchString(output) {
|
|
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
|
|
return
|
|
}
|
|
}
|
|
}
|