additional tests and dronefile
This commit is contained in:
parent
077c3f2ac1
commit
281af45288
24
.drone.yml
Normal file
24
.drone.yml
Normal file
@ -0,0 +1,24 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: install
|
||||
image: golang:1.15
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go
|
||||
commands:
|
||||
- go test -i server/...
|
||||
|
||||
- name: test
|
||||
image: golang:1.15
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go
|
||||
commands:
|
||||
- go test server/...
|
||||
|
||||
volumes:
|
||||
- name: cache
|
||||
temp: {}
|
@ -3,6 +3,7 @@ package tcp
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"mpbl3p/proxy"
|
||||
"net"
|
||||
@ -92,6 +93,7 @@ func (f *Flow) produceMarshalled() ([]byte, error) {
|
||||
if n, err := io.LimitReader(f.conn, 4).Read(lengthBytes); err != nil {
|
||||
return nil, err
|
||||
} else if n != 4 {
|
||||
fmt.Println(n)
|
||||
return nil, ErrNotEnoughBytes
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package tcp
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"github.com/go-playground/assert/v2"
|
||||
"github.com/stretchr/testify/require"
|
||||
"mpbl3p/mocks"
|
||||
@ -9,14 +10,12 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
|
||||
|
||||
func TestFlow_Consume(t *testing.T) {
|
||||
testContent := []byte("A test string is the content of this packet.")
|
||||
testPacket := proxy.NewPacket(testContent)
|
||||
testMac := mocks.AlmostUselessMac{}
|
||||
|
||||
t.Run("Output", func(t *testing.T) {
|
||||
t.Run("Length", func(t *testing.T) {
|
||||
testConn := mocks.NewMockPerfectBiConn(100)
|
||||
|
||||
flowA := Flow{conn: testConn.SideA()}
|
||||
@ -28,7 +27,30 @@ func TestFlow_Consume(t *testing.T) {
|
||||
n, err := testConn.SideB().Read(buf)
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.Equal(t, len(testContent) + 8 + 4 + 4, n)
|
||||
assert.Equal(t, uint32(len(testContent) + 8 + 4), binary.LittleEndian.Uint32(buf[:len(buf)-4]))
|
||||
assert.Equal(t, len(testContent)+8+4+4, n)
|
||||
assert.Equal(t, uint32(len(testContent)+8+4), binary.LittleEndian.Uint32(buf[:len(buf)-4]))
|
||||
})
|
||||
}
|
||||
|
||||
func TestFlow_Produce(t *testing.T) {
|
||||
testContent := "A test string is the content of this packet."
|
||||
testMarshalled := []byte("0000" + testContent + "00000000abcd")
|
||||
binary.LittleEndian.PutUint32(testMarshalled, uint32(len(testMarshalled)-4))
|
||||
|
||||
fmt.Println(testMarshalled)
|
||||
|
||||
testMac := mocks.AlmostUselessMac{}
|
||||
|
||||
t.Run("Length", func(t *testing.T) {
|
||||
testConn := mocks.NewMockPerfectBiConn(100)
|
||||
|
||||
flowA := Flow{conn: testConn.SideA()}
|
||||
|
||||
_, err := testConn.SideB().Write(testMarshalled)
|
||||
require.Nil(t, err)
|
||||
|
||||
p, err := flowA.Produce(testMac)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, testContent, string(p.Raw()))
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user