cli/pkg/cmd/agent-task/shared/log_mock.go
Kynan Ware 0fb10fca7d Various log rendering improvements
Updated the LogRenderer interface and implementations to accept *iostreams.IOStreams instead of *iostreams.ColorScheme, enabling access to terminal theme and width for improved markdown rendering. Refactored related code, tests, and mocks to support this change, and enhanced log rendering to better handle markdown and code output for various tool calls.
2025-09-15 10:13:55 -06:00

144 lines
3.8 KiB
Go

// Code generated by moq; DO NOT EDIT.
// github.com/matryer/moq
package shared
import (
"github.com/cli/cli/v2/pkg/iostreams"
"io"
"sync"
)
// Ensure, that LogRendererMock does implement LogRenderer.
// If this is not the case, regenerate this file with moq.
var _ LogRenderer = &LogRendererMock{}
// LogRendererMock is a mock implementation of LogRenderer.
//
// func TestSomethingThatUsesLogRenderer(t *testing.T) {
//
// // make and configure a mocked LogRenderer
// mockedLogRenderer := &LogRendererMock{
// FollowFunc: func(fetcher func() ([]byte, error), w io.Writer, cs *iostreams.IOStreams) error {
// panic("mock out the Follow method")
// },
// RenderFunc: func(logs []byte, w io.Writer, cs *iostreams.IOStreams) (bool, error) {
// panic("mock out the Render method")
// },
// }
//
// // use mockedLogRenderer in code that requires LogRenderer
// // and then make assertions.
//
// }
type LogRendererMock struct {
// FollowFunc mocks the Follow method.
FollowFunc func(fetcher func() ([]byte, error), w io.Writer, cs *iostreams.IOStreams) error
// RenderFunc mocks the Render method.
RenderFunc func(logs []byte, w io.Writer, cs *iostreams.IOStreams) (bool, error)
// calls tracks calls to the methods.
calls struct {
// Follow holds details about calls to the Follow method.
Follow []struct {
// Fetcher is the fetcher argument value.
Fetcher func() ([]byte, error)
// W is the w argument value.
W io.Writer
// Cs is the cs argument value.
Cs *iostreams.IOStreams
}
// Render holds details about calls to the Render method.
Render []struct {
// Logs is the logs argument value.
Logs []byte
// W is the w argument value.
W io.Writer
// Cs is the cs argument value.
Cs *iostreams.IOStreams
}
}
lockFollow sync.RWMutex
lockRender sync.RWMutex
}
// Follow calls FollowFunc.
func (mock *LogRendererMock) Follow(fetcher func() ([]byte, error), w io.Writer, cs *iostreams.IOStreams) error {
if mock.FollowFunc == nil {
panic("LogRendererMock.FollowFunc: method is nil but LogRenderer.Follow was just called")
}
callInfo := struct {
Fetcher func() ([]byte, error)
W io.Writer
Cs *iostreams.IOStreams
}{
Fetcher: fetcher,
W: w,
Cs: cs,
}
mock.lockFollow.Lock()
mock.calls.Follow = append(mock.calls.Follow, callInfo)
mock.lockFollow.Unlock()
return mock.FollowFunc(fetcher, w, cs)
}
// FollowCalls gets all the calls that were made to Follow.
// Check the length with:
//
// len(mockedLogRenderer.FollowCalls())
func (mock *LogRendererMock) FollowCalls() []struct {
Fetcher func() ([]byte, error)
W io.Writer
Cs *iostreams.IOStreams
} {
var calls []struct {
Fetcher func() ([]byte, error)
W io.Writer
Cs *iostreams.IOStreams
}
mock.lockFollow.RLock()
calls = mock.calls.Follow
mock.lockFollow.RUnlock()
return calls
}
// Render calls RenderFunc.
func (mock *LogRendererMock) Render(logs []byte, w io.Writer, cs *iostreams.IOStreams) (bool, error) {
if mock.RenderFunc == nil {
panic("LogRendererMock.RenderFunc: method is nil but LogRenderer.Render was just called")
}
callInfo := struct {
Logs []byte
W io.Writer
Cs *iostreams.IOStreams
}{
Logs: logs,
W: w,
Cs: cs,
}
mock.lockRender.Lock()
mock.calls.Render = append(mock.calls.Render, callInfo)
mock.lockRender.Unlock()
return mock.RenderFunc(logs, w, cs)
}
// RenderCalls gets all the calls that were made to Render.
// Check the length with:
//
// len(mockedLogRenderer.RenderCalls())
func (mock *LogRendererMock) RenderCalls() []struct {
Logs []byte
W io.Writer
Cs *iostreams.IOStreams
} {
var calls []struct {
Logs []byte
W io.Writer
Cs *iostreams.IOStreams
}
mock.lockRender.RLock()
calls = mock.calls.Render
mock.lockRender.RUnlock()
return calls
}