Skip to content

Commit

Permalink
Add unit tests and mocks to stdio_utils and rework workceptor tests t…
Browse files Browse the repository at this point in the history
…o use table driven testing (#813)
  • Loading branch information
AaronH88 authored Aug 28, 2023
1 parent 54ad74b commit 1f265c2
Show file tree
Hide file tree
Showing 5 changed files with 587 additions and 53 deletions.
18 changes: 9 additions & 9 deletions pkg/workceptor/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (kw *kubeUnit) kubeLoggingConnectionHandler(timestamps bool) (io.ReadCloser
return logStream, nil
}

func (kw *kubeUnit) kubeLoggingNoReconnect(streamWait *sync.WaitGroup, stdout *stdoutWriter, stdoutErr *error) {
func (kw *kubeUnit) kubeLoggingNoReconnect(streamWait *sync.WaitGroup, stdout *STDoutWriter, stdoutErr *error) {
// Legacy method, for use on k8s < v1.23.14
// uses io.Copy to stream data from pod to stdout file
// known issues around this, as logstream can terminate due to log rotation
Expand All @@ -190,7 +190,7 @@ func (kw *kubeUnit) kubeLoggingNoReconnect(streamWait *sync.WaitGroup, stdout *s
}
}

func (kw *kubeUnit) kubeLoggingWithReconnect(streamWait *sync.WaitGroup, stdout *stdoutWriter, stdinErr *error, stdoutErr *error) {
func (kw *kubeUnit) kubeLoggingWithReconnect(streamWait *sync.WaitGroup, stdout *STDoutWriter, stdinErr *error, stdoutErr *error) {
// preferred method for k8s >= 1.23.14
defer streamWait.Done()
var sinceTime time.Time
Expand Down Expand Up @@ -452,7 +452,7 @@ func (kw *kubeUnit) createPod(env map[string]string) error {

return err
} else if err != nil { // any other error besides ErrPodCompleted
stdout, err2 := newStdoutWriter(kw.UnitDir())
stdout, err2 := NewStdoutWriter(FileSystem{}, kw.UnitDir())
if err2 != nil {
errMsg := fmt.Sprintf("Error opening stdout file: %s", err2)
kw.Error(errMsg)
Expand Down Expand Up @@ -606,10 +606,10 @@ func (kw *kubeUnit) runWorkUsingLogger() {
stdinErrChan := make(chan struct{}) // signal that stdin goroutine have errored and stop stdout goroutine

// open stdin reader that reads from the work unit's data directory
var stdin *stdinReader
var stdin *STDinReader
if !skipStdin {
var err error
stdin, err = newStdinReader(kw.UnitDir())
stdin, err = NewStdinReader(FileSystem{}, kw.UnitDir())
if err != nil {
if errors.Is(err, errFileSizeZero) {
skipStdin = true
Expand Down Expand Up @@ -637,7 +637,7 @@ func (kw *kubeUnit) runWorkUsingLogger() {
}

// open stdout writer that writes to work unit's data directory
stdout, err := newStdoutWriter(kw.UnitDir())
stdout, err := NewStdoutWriter(FileSystem{}, kw.UnitDir())
if err != nil {
errMsg := fmt.Sprintf("Error opening stdout file: %s", err)
kw.Error(errMsg)
Expand Down Expand Up @@ -950,8 +950,8 @@ func (kw *kubeUnit) runWorkUsingTCP() {
}

// Open stdin reader
var stdin *stdinReader
stdin, err = newStdinReader(kw.UnitDir())
var stdin *STDinReader
stdin, err = NewStdinReader(FileSystem{}, kw.UnitDir())
if err != nil {
errMsg := fmt.Sprintf("Error opening stdin file: %s", err)
kw.w.nc.GetLogger().Error(errMsg)
Expand All @@ -962,7 +962,7 @@ func (kw *kubeUnit) runWorkUsingTCP() {
}

// Open stdout writer
stdout, err := newStdoutWriter(kw.UnitDir())
stdout, err := NewStdoutWriter(FileSystem{}, kw.UnitDir())
if err != nil {
errMsg := fmt.Sprintf("Error opening stdout file: %s", err)
kw.w.nc.GetLogger().Error(errMsg)
Expand Down
183 changes: 183 additions & 0 deletions pkg/workceptor/mock_workceptor/stdio_utils.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1f265c2

Please sign in to comment.