Skip to content

Commit

Permalink
tests: add criteria_test.go
Browse files Browse the repository at this point in the history
This is the start of running tests against the main parts of
ShellAndTest. More to come.
  • Loading branch information
mattburchett committed Oct 8, 2022
1 parent 58a7723 commit 0c4e909
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions internal/shelltest/criteria_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package shelltest

import (
"fmt"
"sync/atomic"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func TestTasksRunnerWithError(t *testing.T) {
var errCounter = atomic.Int32{}
errCount := make(chan int32)
defer close(errCount)
go func() {
// NOTE(mattburchett):
// I don't love having to put this sleep here, but in testing, it seems to get data
// to quickly and causes the output to return zero. Maybe there's a better way...
time.Sleep(1 * time.Second)
current := int32(0)
fmt.Println("foobar")
for {
current = <-errCount
errCounter.Add(current)
}
}()

tasks := []string{"eecho foo", "eecho bar"}
err := tasksRunner(tasks, false, errCount)
assert.Error(t, err)
assert.Equal(t, errCounter.Load(), int32(2))
}

func TestTasksRunnerWithNoError(t *testing.T) {
var errCounter = atomic.Int32{}
errCount := make(chan int32)
defer close(errCount)
go func() {
// NOTE(mattburchett):
// I don't love having to put this sleep here, but in testing, it seems to get data
// too quickly and causes the output to return zero. Maybe there's a better way...
time.Sleep(1 * time.Second)
current := int32(0)
fmt.Println("foobar")
for {
current = <-errCount
errCounter.Add(current)
}
}()

tasks := []string{"echo foo", "echo bar"}
err := tasksRunner(tasks, false, errCount)
assert.NoError(t, err)
assert.Equal(t, errCounter.Load(), int32(0))
}

0 comments on commit 0c4e909

Please sign in to comment.