-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is the start of running tests against the main parts of ShellAndTest. More to come.
- Loading branch information
1 parent
58a7723
commit 0c4e909
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |