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 // Maybe print output
if hj.Reader != nil { if hj.Reader != nil {
slog.Debugf("%s: Getting exec reader", job.name)
for scanner.Scan() { for scanner.Scan() {
slog.Debugf("%s: Getting exec line", job.name)
line := scanner.Text() line := scanner.Text()
if len(line) > 0 { if len(line) > 0 {
slog.Infof("%s: Exec output: %s", job.name, line) slog.Infof("%s: Exec output: %s", job.name, line)

View File

@ -1,11 +1,13 @@
package main package main
import ( import (
"bufio"
"errors" "errors"
"fmt" "fmt"
"log" "log"
"reflect" "reflect"
"sort" "sort"
"strings"
"testing" "testing"
dockerTypes "github.com/docker/docker/api/types" 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) { 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 // NewFakeDockerClient creates an empty client