2023-03-28 22:48:58 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 22:48:58 +00:00
|
|
|
|
2020-09-17 21:43:04 +00:00
|
|
|
package lib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"testing"
|
|
|
|
|
2022-02-14 17:45:45 +00:00
|
|
|
"github.com/hashicorp/consul-net-rpc/net/rpc"
|
2020-09-17 21:43:04 +00:00
|
|
|
"github.com/hashicorp/yamux"
|
2022-02-14 17:45:45 +00:00
|
|
|
|
2020-09-17 21:43:04 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestErrIsEOF(t *testing.T) {
|
|
|
|
var tests = []struct {
|
|
|
|
name string
|
|
|
|
err error
|
|
|
|
}{
|
|
|
|
{name: "EOF", err: io.EOF},
|
2020-09-19 01:59:04 +00:00
|
|
|
{name: "Wrapped EOF", err: fmt.Errorf("test: %w", io.EOF)},
|
2020-09-17 21:43:04 +00:00
|
|
|
{name: "yamuxStreamClosed", err: yamux.ErrStreamClosed},
|
|
|
|
{name: "yamuxSessionShutdown", err: yamux.ErrSessionShutdown},
|
2020-09-19 01:59:04 +00:00
|
|
|
{name: "ServerError(___: EOF)", err: rpc.ServerError(fmt.Sprintf("rpc error: %s", io.EOF.Error()))},
|
|
|
|
{name: "Wrapped ServerError(___: EOF)", err: fmt.Errorf("rpc error: %w", rpc.ServerError(fmt.Sprintf("rpc error: %s", io.EOF.Error())))},
|
2020-09-17 21:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
require.True(t, IsErrEOF(tt.err))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|