"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pkg/tcp/proxy_test.go" between
traefik-v2.3.2.src.tar.gz and traefik-v2.3.3.src.tar.gz

About: Traefik is a cloud native edge router, a reverse proxy and load balancer for HTTP and TCP-based applications.

proxy_test.go  (traefik-v2.3.2.src):proxy_test.go  (traefik-v2.3.3.src)
package tcp package tcp
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"net" "net"
"sync"
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func fakeRedis(t *testing.T, listener net.Listener) { func fakeRedis(t *testing.T, listener net.Listener) {
for { for {
conn, err := listener.Accept() conn, err := listener.Accept()
fmt.Println("Accept on server") fmt.Println("Accept on server")
require.NoError(t, err) require.NoError(t, err)
for { for {
withErr := false withErr := false
skipping to change at line 82 skipping to change at line 84
err = conn.(*net.TCPConn).CloseWrite() err = conn.(*net.TCPConn).CloseWrite()
require.NoError(t, err) require.NoError(t, err)
var buf []byte var buf []byte
buffer := bytes.NewBuffer(buf) buffer := bytes.NewBuffer(buf)
n, err := io.Copy(buffer, conn) n, err := io.Copy(buffer, conn)
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, int64(4), n) require.Equal(t, int64(4), n)
require.Equal(t, "PONG", buffer.String()) require.Equal(t, "PONG", buffer.String())
} }
func TestLookupAddress(t *testing.T) {
testCases := []struct {
desc string
address string
expectSame assert.ComparisonAssertionFunc
}{
{
desc: "IP doesn't need refresh",
address: "8.8.4.4:53",
expectSame: assert.Same,
},
{
desc: "Hostname needs refresh",
address: "dns.google:53",
expectSame: assert.NotSame,
},
}
for _, test := range testCases {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
proxy, err := NewProxy(test.address, 10*time.Millisecond)
require.NoError(t, err)
require.NotNil(t, proxy.target)
proxyListener, err := net.Listen("tcp", ":0")
require.NoError(t, err)
var wg sync.WaitGroup
go func(wg *sync.WaitGroup) {
for {
conn, err := proxyListener.Accept()
require.NoError(t, err)
proxy.ServeTCP(conn.(*net.TCPConn))
wg.Done()
}
}(&wg)
var lastTarget *net.TCPAddr
for i := 0; i < 3; i++ {
wg.Add(1)
conn, err := net.Dial("tcp", proxyListener.Addr()
.String())
require.NoError(t, err)
_, err = conn.Write([]byte("ping\n"))
require.NoError(t, err)
err = conn.Close()
require.NoError(t, err)
wg.Wait()
assert.NotNil(t, proxy.target)
if lastTarget != nil {
test.expectSame(t, lastTarget, proxy.targ
et)
}
lastTarget = proxy.target
}
})
}
}
 End of changes. 3 change blocks. 
0 lines changed or deleted 2 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)