1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-11 07:03:32 +08:00
Files
kubo/util/do_test.go
Ho-Sheng Hsiao bf22aeec0a Reorged imports from jbenet/go-ipfs to ipfs/go-ipfs
- Modified Godeps/Godeps.json by hand
- [TEST] Updated welcome docs hash to sharness
- [TEST] Updated contact doc
- [TEST] disabled breaking test (t0080-repo refs local)
2015-03-31 12:52:25 -07:00

43 lines
783 B
Go

package util
import (
"errors"
"testing"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
)
func TestDoReturnsContextErr(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
ch := make(chan struct{})
err := ContextDo(ctx, func() error {
cancel()
ch <- struct{}{} // won't return
return nil
})
if err != ctx.Err() {
t.Fail()
}
}
func TestDoReturnsFuncError(t *testing.T) {
ctx := context.Background()
expected := errors.New("expected to be returned by ContextDo")
err := ContextDo(ctx, func() error {
return expected
})
if err != expected {
t.Fail()
}
}
func TestDoReturnsNil(t *testing.T) {
ctx := context.Background()
err := ContextDo(ctx, func() error {
return nil
})
if err != nil {
t.Fail()
}
}