fix the test that should have caught the problem

This commit is contained in:
Daisuke Maki 2016-12-17 07:13:09 +09:00
parent 08582ac4a8
commit d8c7102efd

View file

@ -264,6 +264,9 @@ func TestApplyConfig(t *testing.T) {
}
}
// While this issue is labeled for Issue363, it tests against 376 as well.
// The test should have caught the bug for 376, but the premise of the test
// itself was wrong
func TestGHIssue363(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
@ -273,15 +276,25 @@ func TestGHIssue363(t *testing.T) {
p.Stdin = bytes.NewBufferString("foo\n")
var out bytes.Buffer
p.Stdout = &out
if !assert.NoError(t, p.Run(ctx), "p.Run should succeed") {
return
}
resultCh := make(chan error)
go func() {
defer close(resultCh)
select {
case <-ctx.Done():
return
case resultCh <- p.Run(ctx):
return
}
}()
select {
case <-ctx.Done():
t.Errorf("we should get here before being canceled")
return
default:
t.Errorf("timeout reached")
case err := <-resultCh:
if !assert.True(t, util.IsCollectResultsError(err), "isCollectResultsError") {
return
}
}
if !assert.NotEqual(t, "foo\n", out.String(), "output should match") {