Improve test coverage by mocking exec output
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build is failing

This commit is contained in:
IamTheFij 2024-09-26 12:01:12 -07:00
parent a0df55a60c
commit d87bdd451d
2 changed files with 5 additions and 4 deletions

View File

@ -186,10 +186,7 @@ func (job ContainerExecJob) Run() {
// Maybe print output
if hj.Reader != nil {
slog.Debugf("%s: Getting exec reader", job.name)
for scanner.Scan() {
slog.Debugf("%s: Getting exec line", job.name)
line := scanner.Text()
if len(line) > 0 {
slog.Infof("%s: Exec output: %s", job.name, line)

View File

@ -1,11 +1,13 @@
package main
import (
"bufio"
"errors"
"fmt"
"log"
"reflect"
"sort"
"strings"
"testing"
dockerTypes "github.com/docker/docker/api/types"
@ -145,7 +147,9 @@ func (fakeClient *FakeDockerClient) ContainerInspect(ctx context.Context, contai
}
func (fakeClient *FakeDockerClient) ContainerExecAttach(ctx context.Context, execID string, options container.ExecAttachOptions) (dockerTypes.HijackedResponse, error) {
return dockerTypes.HijackedResponse{}, nil
return dockerTypes.HijackedResponse{
Reader: bufio.NewReader(strings.NewReader("Some output from our command")),
}, nil
}
// NewFakeDockerClient creates an empty client