Browse Source

boundary detection tests

flashmob 6 years ago
parent
commit
8e6ecb6417
2 changed files with 17 additions and 11 deletions
  1. 3 3
      backends/s_mime.go
  2. 14 8
      backends/s_mime_test.go

+ 3 - 3
backends/s_mime.go

@@ -171,6 +171,9 @@ func (p *parser) peek() byte {
 
 // simulate a byte stream
 func (p *parser) inject(input ...[]byte) {
+	p.set(input[0])
+	p.pos = 0
+	p.ch = p.buf[0]
 	go func() {
 		for i := 1; i < len(input); i++ {
 			<-p.consumed
@@ -180,9 +183,6 @@ func (p *parser) inject(input ...[]byte) {
 		<-p.consumed
 		p.gotNewSlice <- false // no more data
 	}()
-	p.set(input[0])
-	p.pos = 0
-	p.ch = p.buf[0]
 }
 
 func (p *parser) set(input []byte) {

+ 14 - 8
backends/s_mime_test.go

@@ -154,26 +154,32 @@ func TestBoundary(t *testing.T) {
 		t.Error(err)
 	}
 
+	//for c := p.next(); c != 0; c= p.next() {} // drain
+
 	p.inject([]byte("The quick brown fox jumped over the lazy dog-wololo-"))
 	err = p.boundary(part)
 	if err != nil {
 		t.Error(err)
 	}
 
-	// the boundary with an additional buffer in between
-	p.inject([]byte("The quick brown fox jumped over the lazy dog"),
-		[]byte("this is the middle"),
-		[]byte("and thats the end-wololo-"))
+	for c := p.next(); c != 0; c = p.next() {
+	} // drain
 
+	// boundary is split over multiple slices
+	p.inject(
+		[]byte("The quick brown fox jumped ov-wolo"),
+		[]byte("lo-er the lazy dog"))
 	err = p.boundary(part)
 	if err != nil {
 		t.Error(err)
 	}
+	for c := p.next(); c != 0; c = p.next() {
+	} // drain
+	// the boundary with an additional buffer in between
+	p.inject([]byte("The quick brown fox jumped over the lazy dog"),
+		[]byte("this is the middle"),
+		[]byte("and thats the end-wololo-"))
 
-	// boundary is split over multiple slices
-	p.inject(
-		[]byte("The quick brown fox jumped ov-wolo"),
-		[]byte("lo-er the lazy dog"))
 	err = p.boundary(part)
 	if err != nil {
 		t.Error(err)