diff options
| author | Grégoire Duchêne <gduchene@awhk.org> | 2022-06-05 18:01:39 +0100 |
|---|---|---|
| committer | Grégoire Duchêne <gduchene@awhk.org> | 2022-06-05 18:01:39 +0100 |
| commit | 0315338ef5c5fadd739088684323b82535fc904b (patch) | |
| tree | c7febbf73ef122cd7c46f3e6e81c09432c8d4987 /net_test.go | |
| parent | 326a741c1298959e5d6e5eb1a6b2225ef9151063 (diff) | |
Add Listen, Must, PipeListener, and T
Diffstat (limited to 'net_test.go')
| -rw-r--r-- | net_test.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/net_test.go b/net_test.go new file mode 100644 index 0000000..505579e --- /dev/null +++ b/net_test.go @@ -0,0 +1,50 @@ +package core_test + +import ( + "context" + "syscall" + "testing" + + "go.awhk.org/core" +) + +func TestPipeListener(s *testing.T) { + t := core.T{T: s} + + t.Run("Success", func(t *core.T) { + p := &core.PipeListener{} + + t.Go(func() { + conn, err := p.Accept() + t.AssertErrorIs(nil, err) + t.AssertNotEqual(nil, conn) + }) + + conn, err := p.Dial("", "") + t.AssertErrorIs(nil, err) + t.AssertNotEqual(nil, conn) + }) + + t.Run("WhenClosed", func(t *core.T) { + p := &core.PipeListener{} + p.Close() + + conn, err := p.Accept() + t.AssertErrorIs(syscall.EINVAL, err) + t.AssertEqual(nil, conn) + + conn, err = p.Dial("", "") + t.AssertErrorIs(syscall.ECONNREFUSED, err) + t.AssertEqual(nil, conn) + }) + + t.Run("WhenContextCanceled", func(t *core.T) { + p := &core.PipeListener{} + + ctx, cancel := context.WithCancel(context.Background()) + cancel() + conn, err := p.DialContext(ctx, "", "") + t.AssertErrorIs(context.Canceled, err) + t.AssertEqual(nil, conn) + }) +} |
