Improve test coverage by mocking exec output
This commit is contained in:
parent
a0df55a60c
commit
d87bdd451d
3
main.go
3
main.go
@ -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)
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user