-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
195 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package tcp_test | ||
|
||
import ( | ||
"errors" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/matryer/is" | ||
"github.com/rvflash/tcp" | ||
) | ||
|
||
const ( | ||
hiWorld = "hello world" | ||
prefix = "tcp: " | ||
) | ||
|
||
func TestNewError(t *testing.T) { | ||
var ( | ||
dt = []struct { | ||
in string | ||
err error | ||
out string | ||
}{ | ||
{out: prefix}, | ||
{in: "hi!", out: prefix + "hi!"}, | ||
{in: "hello", err: errors.New("world"), out: prefix + "hello: world"}, | ||
} | ||
are = is.New(t) | ||
err error | ||
) | ||
for i, tt := range dt { | ||
t.Run("#"+strconv.Itoa(i), func(t *testing.T) { | ||
err = tcp.NewError(tt.in, tt.err) | ||
are.Equal(err.Error(), tt.out) | ||
}) | ||
} | ||
} | ||
|
||
func TestError_Recovered(t *testing.T) { | ||
e := &tcp.Error{} | ||
is.New(t).True(!e.Recovered()) | ||
} | ||
|
||
func TestErrors_Error(t *testing.T) { | ||
var err tcp.Errors | ||
err = append(err, errors.New(hiWorld)) | ||
err = append(err, tcp.NewError(hiWorld)) | ||
are := is.New(t) | ||
are.Equal(err.Error(), hiWorld+", "+prefix+hiWorld) | ||
} | ||
|
||
func TestErrors_Recovered(t *testing.T) { | ||
var ( | ||
dt = []struct { | ||
err tcp.Errors | ||
ok bool | ||
}{ | ||
{err: tcp.Errors{}}, | ||
{err: tcp.Errors{tcp.NewError(hiWorld)}, ok: true}, | ||
} | ||
are = is.New(t) | ||
) | ||
for i, tt := range dt { | ||
t.Run("#"+strconv.Itoa(i), func(t *testing.T) { | ||
are.Equal(tt.err.Recovered(), tt.ok) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
module github.com/rvflash/tcp | ||
|
||
require github.com/sirupsen/logrus v1.3.0 | ||
require ( | ||
github.com/matryer/is v1.2.0 | ||
github.com/sirupsen/logrus v1.3.0 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package tcp_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/rvflash/tcp" | ||
) | ||
|
||
func TestRecovery(t *testing.T) { | ||
srv := tcp.New() | ||
srv.Use(tcp.Recovery()) | ||
req := tcp.NewRequest(tcp.SYN, nil) | ||
w := tcp.NewRecorder() | ||
srv.ServeTCP(w, req) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.