Ver código fonte

Fix test break

Darien Raymond 9 anos atrás
pai
commit
6d0915cc8c
3 arquivos alterados com 24 adições e 23 exclusões
  1. 1 0
      common/alloc/buffer.go
  2. 22 22
      common/crypto/auth.go
  3. 1 1
      common/io/reader_test.go

+ 1 - 0
common/alloc/buffer.go

@@ -108,6 +108,7 @@ func (b *Buffer) Bytes() []byte {
 }
 
 func (b *Buffer) SetBytesFunc(writer BytesWriter) {
+	b.start = defaultOffset
 	b.end = b.start + writer(b.v[b.start:])
 }
 

+ 22 - 22
common/crypto/auth.go

@@ -121,38 +121,38 @@ func (v *AuthenticationReader) CopyChunk(b []byte) int {
 	return nBytes
 }
 
-func (v *AuthenticationReader) Read(b []byte) (int, error) {
-	if len(v.chunk) > 0 {
-		nBytes := v.CopyChunk(b)
-		return nBytes, nil
-	}
-
-	totalBytes := 0
+func (v *AuthenticationReader) EnsureChunk() error {
 	for {
 		err := v.NextChunk()
+		if err == nil {
+			return nil
+		}
 		if err == errInsufficientBuffer {
-			if totalBytes > 0 {
-				return totalBytes, nil
+			if !v.buffer.IsEmpty() {
+				leftover := v.buffer.Bytes()
+				v.buffer.SetBytesFunc(func(b []byte) int {
+					return copy(b, leftover)
+				})
 			}
-			leftover := v.buffer.Bytes()
-			v.buffer.SetBytesFunc(func(b []byte) int {
-				return copy(b, leftover)
-			})
 			_, err = v.buffer.FillFrom(v.reader)
 		}
+		return err
+	}
+}
 
-		if err != nil {
-			return 0, err
-		}
-
+func (v *AuthenticationReader) Read(b []byte) (int, error) {
+	if len(v.chunk) > 0 {
 		nBytes := v.CopyChunk(b)
-		b = b[nBytes:]
-		totalBytes += nBytes
+		return nBytes, nil
+	}
 
-		if !v.aggressive {
-			return totalBytes, nil
-		}
+	err := v.EnsureChunk()
+	if err != nil {
+		return 0, err
 	}
+
+	nBytes := v.CopyChunk(b)
+	return nBytes, nil
 }
 
 type AuthenticationWriter struct {

+ 1 - 1
common/io/reader_test.go

@@ -25,5 +25,5 @@ func TestAdaptiveReader(t *testing.T) {
 	b2, err := reader.Read()
 	assert.Error(err).IsNil()
 	assert.Bool(b2.IsFull()).IsTrue()
-	assert.Int(buffer.Len()).Equals(778272)
+	assert.Int(buffer.Len()).Equals(1007648)
 }