1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

test case for http auth

This commit is contained in:
Darien Raymond 2016-11-04 21:59:19 +01:00
parent 80312627c4
commit bae0de7d95
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 29 additions and 0 deletions

View File

@ -41,6 +41,12 @@ type HeaderWriter struct {
header *alloc.Buffer
}
func NewHeaderWriter(header *alloc.Buffer) *HeaderWriter {
return &HeaderWriter{
header: header,
}
}
func (this *HeaderWriter) Write(writer io.Writer) error {
if this.header == nil {
return nil

View File

@ -0,0 +1,23 @@
package http_test
import (
"testing"
"v2ray.com/core/common/alloc"
"v2ray.com/core/testing/assert"
. "v2ray.com/core/transport/internet/authenticators/http"
)
func TestReaderWriter(t *testing.T) {
assert := assert.On(t)
cache := alloc.NewBuffer()
writer := NewHeaderWriter(alloc.NewLocalBuffer(256).Clear().AppendString("abcd" + ENDING))
writer.Write(cache)
cache.Write([]byte{'e', 'f', 'g'})
reader := &HeaderReader{}
buffer, err := reader.Read(cache)
assert.Error(err).IsNil()
assert.Bytes(buffer.Value).Equals([]byte{'e', 'f', 'g'})
}