From 0e64d73f83c8b0fea4c5fb0dbc29c30abda07976 Mon Sep 17 00:00:00 2001 From: Pierre Cauchois Date: Thu, 17 Sep 2020 21:43:04 +0000 Subject: [PATCH] Add unit tests for isErrEOF() --- lib/eof_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lib/eof_test.go diff --git a/lib/eof_test.go b/lib/eof_test.go new file mode 100644 index 0000000000..b3810f1c87 --- /dev/null +++ b/lib/eof_test.go @@ -0,0 +1,38 @@ +package lib + +import ( + "fmt" + "io" + "testing" + + "github.com/hashicorp/yamux" + "github.com/stretchr/testify/require" +) + +func TestErrIsEOF(t *testing.T) { + t.Parallel() + + var tests = []struct { + name string + err error + }{ + {name: "EOF", err: io.EOF}, + {name: "yamuxStreamClosed", err: yamux.ErrStreamClosed}, + {name: "yamuxSessionShutdown", err: yamux.ErrSessionShutdown}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + require.True(t, IsErrEOF(tt.err)) + }) + t.Run(fmt.Sprintf("Wrapped %s", tt.name), func(t *testing.T) { + t.Parallel() + require.True(t, IsErrEOF(fmt.Errorf("test: %w", tt.err))) + }) + t.Run(fmt.Sprintf("String suffix is %s", tt.name), func(t *testing.T) { + t.Parallel() + require.True(t, IsErrEOF(fmt.Errorf("rpc error: %s", tt.err.Error()))) + }) + } +}