forked from v2fly/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
9e66f31
commit c7f847c
Showing
5 changed files
with
177 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package buf_test | ||
|
||
import ( | ||
"crypto/rand" | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
|
||
"v2ray.com/core/common/buf" | ||
"v2ray.com/core/common/errors" | ||
"v2ray.com/core/testing/mocks" | ||
) | ||
|
||
func TestReadError(t *testing.T) { | ||
mockCtl := gomock.NewController(t) | ||
defer mockCtl.Finish() | ||
|
||
mockReader := mocks.NewReader(mockCtl) | ||
mockReader.EXPECT().Read(gomock.Any()).Return(0, errors.New("error")) | ||
|
||
err := buf.Copy(buf.NewReader(mockReader), buf.Discard) | ||
if err == nil { | ||
t.Fatal("expected error, but nil") | ||
} | ||
|
||
if !buf.IsReadError(err) { | ||
t.Error("expected to be ReadError, but not") | ||
} | ||
|
||
if err.Error() != "error" { | ||
t.Fatal("unexpected error message: ", err.Error()) | ||
} | ||
} | ||
|
||
func TestWriteError(t *testing.T) { | ||
mockCtl := gomock.NewController(t) | ||
defer mockCtl.Finish() | ||
|
||
mockWriter := mocks.NewWriter(mockCtl) | ||
mockWriter.EXPECT().Write(gomock.Any()).Return(0, errors.New("error")) | ||
|
||
err := buf.Copy(buf.NewReader(rand.Reader), buf.NewWriter(mockWriter)) | ||
if err == nil { | ||
t.Fatal("expected error, but nil") | ||
} | ||
|
||
if !buf.IsWriteError(err) { | ||
t.Error("expected to be WriteError, but not") | ||
} | ||
|
||
if err.Error() != "error" { | ||
t.Fatal("unexpected error message: ", err.Error()) | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.