Skip to content

Commit

Permalink
test: test and lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hairyhum committed Feb 12, 2024
1 parent 76c51eb commit e24c134
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
4 changes: 0 additions & 4 deletions pkg/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,3 @@ func fPrintOutput(w io.Writer, key, value string) error {
fmt.Fprintln(w, PhaseOpString, outString)
return nil
}

const reStr = PhaseOpString + `(.*)$`

var logRE = regexp.MustCompile(reStr)
4 changes: 4 additions & 0 deletions pkg/output/output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ import (
"context"
"io"
"strings"
"testing"

. "gopkg.in/check.v1"
)

// Hook up gocheck into the "go test" runner.
func Test(t *testing.T) { TestingT(t) }

type OutputSuite struct{}

var _ = Suite(&OutputSuite{})
Expand Down
22 changes: 11 additions & 11 deletions pkg/output/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,18 @@ func splitLines(ctx context.Context, r io.ReadCloser, f func(context.Context, []
if len(line) == 0 {
continue
}
if state.readingOutput {
switch {
case state.readingOutput:
if state, err = handleOutput(state, line, isPrefix, ctx, f); err != nil {
return err
}
} else {
if len(state.separatorSuffix) > 0 {
if state, err = handleSeparatorSuffix(state, line, isPrefix, ctx, f); err != nil {
return err
}
} else {
if state, err = handleLog(line, isPrefix, ctx, f); err != nil {
return err
}
case len(state.separatorSuffix) > 0:
if state, err = handleSeparatorSuffix(state, line, isPrefix, ctx, f); err != nil {
return err
}
default:
if state, err = handleLog(line, isPrefix, ctx, f); err != nil {
return err
}
}
}
Expand Down Expand Up @@ -109,7 +108,8 @@ func handleOutput(state scanState, line []byte, isPrefix bool, ctx context.Conte
return ReadPhaseOutputState(append(state.outputBuf, line...)), nil
} else {
// Reached the end of the line while reading phase output
outputContent := append(state.outputBuf, line...)
outputContent := state.outputBuf
outputContent = append(outputContent, line...)

if err := f(ctx, outputContent); err != nil {
return state, err
Expand Down
24 changes: 24 additions & 0 deletions pkg/output/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,27 @@ func (s *OutputTestSuite) TestShortStreamsWithPhaseOutput(c *C) {
c.Check(len(m), Equals, 1)
c.Check(m[cases[0].key], Equals, string(cases[0].value))
}

func (s *OutputTestSuite) TestLongStreamsWithPhaseOutput(c *C) {
done := make(chan struct{})
defer func() { close(done) }()

cases := generateTestCases(10, 10000, 10, 50, EndlineRequired)
r := getTestReaderCloser(done, cases)
m, e := output.LogAndParse(context.TODO(), r)
c.Check(e, IsNil)
c.Check(len(m), Equals, 10)
c.Check(m[cases[0].key], Equals, string(cases[0].value))
}

func (s *OutputTestSuite) TestHugeStreamsWithPhaseOutput(c *C) {
done := make(chan struct{})
defer func() { close(done) }()

cases := generateTestCases(5, 100000, 10, 50, EndlineRequired)
r := getTestReaderCloser(done, cases)
m, e := output.LogAndParse(context.TODO(), r)
c.Check(e, IsNil)
c.Check(len(m), Equals, 5)
c.Check(m[cases[0].key], Equals, string(cases[0].value))
}

0 comments on commit e24c134

Please sign in to comment.