Skip to content

Commit

Permalink
Fixes for failing tests
Browse files Browse the repository at this point in the history
Signed-off-by: Kimmo Lehto <[email protected]>
  • Loading branch information
kke committed Mar 7, 2024
1 parent 09cb7a1 commit 959d52f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
1 change: 0 additions & 1 deletion aliases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ func TestGetOSRelease(t *testing.T) {
return nil
})

t.Log("getting release")
os, err := rig.GetOSRelease(mr)
require.NoError(t, err)
require.Equal(t, "Foo", os.Name)
Expand Down
15 changes: 12 additions & 3 deletions kv/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,10 @@ func (d *Decoder) Decode(obj any) (err error) { //nolint:cyclop
reader := bufio.NewReader(d.r)
for {
line, readErr := reader.ReadString(d.rdelim)
if readErr != nil && !errors.Is(readErr, io.EOF) {
if line == "" && readErr != nil {
if errors.Is(readErr, io.EOF) {
return nil
}
return fmt.Errorf("read: %w", readErr)
}

Expand All @@ -433,8 +436,14 @@ func (d *Decoder) Decode(obj any) (err error) { //nolint:cyclop
}
}

if errors.Is(readErr, io.EOF) {
return nil
// TODO Something somewhere returns non-empty string and io.EOF in the same call
// so the error has to be handled twice per loop. It may be a bug in the ExecScanner
// implementation or in the mock runner.
if readErr != nil {
if errors.Is(readErr, io.EOF) {
return nil
}
return fmt.Errorf("read: %w", readErr)
}
}
}
12 changes: 12 additions & 0 deletions rigtest/mocklogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ func TraceToStderr() {
log.SetTraceLogger(slog.New(slog.NewTextHandler(os.Stderr, nil)))
}

// TraceOff sets the trace logger to null.
func TraceOff() {
log.SetTraceLogger(log.Null)
}

// Trace allows running a function with trace logging enabled.
func Trace(fn func()) {
TraceToStderr()
fn()
defer TraceOff()
}

// MockLogMessage is a mock log message.
type MockLogMessage struct {
level int
Expand Down

0 comments on commit 959d52f

Please sign in to comment.