Skip to content

Commit

Permalink
Merge pull request #291 from ayuryshev/feature/remove-dupl-tests-290
Browse files Browse the repository at this point in the history
Remove duplicated tests in pkg/router/router_test.go and internal/therealssh/client_test.go
  • Loading branch information
ayuryshev authored Apr 16, 2019
2 parents 3bfd735 + 1bdeee2 commit bf39234
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 140 deletions.
19 changes: 3 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,10 @@ vendorcheck: ## Run vendorcheck
#GO111MODULE=off vendorcheck ./cmd/therealssh-cli/...

test: ## Run tests for net
-go clean -testcache
-go clean -testcache &>/dev/null
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./internal/...
#${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/app/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/cipher/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/manager/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/messaging-discovery/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/node/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/route-finder/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/router/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/routing/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/setup/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/transport/...
${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/transport-discovery/...
${OPTS} go test -tags no_ci -cover -timeout=5m ./pkg/messaging/...


${OPTS} go test -race -tags no_ci -cover -timeout=5m ./pkg/...

install-linters: ## Install linters
- VERSION=1.13.2 ./ci_scripts/install-golangci-lint.sh
# GO111MODULE=off go get -u github.com/FiloSottile/vendorcheck
Expand Down
38 changes: 0 additions & 38 deletions internal/therealssh/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,44 +85,6 @@ func TestClientHandleResponse(t *testing.T) {
assert.Equal(t, []byte("foo"), <-dataCh)
}

func TestClientHandleData(t *testing.T) {
pk, _ := cipher.GenerateKeyPair()
c := &Client{nil, newChanList()}
in, out := net.Pipe()
errCh := make(chan error)
go func() {
errCh <- c.serveConn(&mockConn{out, &app.Addr{PubKey: pk, Port: Port}})
}()

_, err := in.Write(appendU32([]byte{byte(CmdChannelData)}, 0))
require.NoError(t, err)
assert.Equal(t, "channel is not opened", (<-errCh).Error())

go func() {
errCh <- c.serveConn(&mockConn{out, &app.Addr{PubKey: cipher.PubKey{}, Port: Port}})
}()

ch := OpenChannel(4, &app.Addr{PubKey: pk, Port: Port}, nil)
c.chans.add(ch)

_, err = in.Write(appendU32([]byte{byte(CmdChannelData)}, 0))
require.NoError(t, err)
assert.Equal(t, "unauthorized", (<-errCh).Error())

go func() {
errCh <- c.serveConn(&mockConn{out, &app.Addr{PubKey: pk, Port: Port}})
}()
dataCh := make(chan []byte)
go func() {
dataCh <- <-ch.dataCh
}()

data := append(appendU32([]byte{byte(CmdChannelData)}, 0), []byte("foo")...)
_, err = in.Write(data)
require.NoError(t, err)
assert.Equal(t, []byte("foo"), <-dataCh)
}

type pipeDialer struct {
conn net.Conn
}
Expand Down
86 changes: 0 additions & 86 deletions pkg/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,92 +733,6 @@ func TestRouterCloseLoopOnAppClose(t *testing.T) {
require.Nil(t, rule)
}

func TestRouterCloseLoopOnRouterClose(t *testing.T) {
client := transport.NewDiscoveryMock()
logStore := transport.InMemoryTransportLogStore()

pk1, sk1 := cipher.GenerateKeyPair()
pk2, sk2 := cipher.GenerateKeyPair()
pk3, _ := cipher.GenerateKeyPair()

f1, f2 := transport.NewMockFactoryPair(pk1, pk2)
f1.SetType("messaging")

m1, err := transport.NewManager(&transport.ManagerConfig{PubKey: pk1, SecKey: sk1, DiscoveryClient: client, LogStore: logStore}, f1)
require.NoError(t, err)

m2, err := transport.NewManager(&transport.ManagerConfig{PubKey: pk2, SecKey: sk2, DiscoveryClient: client, LogStore: logStore}, f2)
require.NoError(t, err)
go m2.Serve(context.TODO()) // nolint: errcheck

rt := routing.InMemoryRoutingTable()
rule := routing.AppRule(time.Now().Add(time.Hour), 4, pk3, 6, 5)
routeID, err := rt.AddRule(rule)
require.NoError(t, err)

conf := &Config{
Logger: logging.MustGetLogger("routesetup"),
PubKey: pk1,
SecKey: sk1,
TransportManager: m1,
RoutingTable: rt,
SetupNodes: []cipher.PubKey{pk2},
}
r := New(conf)
errCh := make(chan error)
go func() {
acceptCh, _ := m2.Observe()
tr := <-acceptCh

proto := setup.NewSetupProtocol(tr)
p, data, err := proto.ReadPacket()
if err != nil {
errCh <- err
return
}

if p != setup.PacketCloseLoop {
errCh <- errors.New("unknown command")
return
}

ld := &setup.LoopData{}
if err := json.Unmarshal(data, ld); err != nil {
errCh <- err
return
}

if ld.LocalPort != 5 || ld.RemotePort != 6 || ld.RemotePK != pk3 {
errCh <- errors.New("invalid payload")
return
}

errCh <- proto.WritePacket(setup.RespSuccess, []byte{})
}()

rw, rwIn := net.Pipe()
go r.ServeApp(rwIn, 5, &app.Config{}) // nolint: errcheck
appProto := app.NewProtocol(rw)
go appProto.Serve(nil) // nolint: errcheck

time.Sleep(100 * time.Millisecond)

raddr := &app.Addr{PubKey: pk3, Port: 6}
require.NoError(t, r.pm.SetLoop(5, raddr, &loop{}))

require.NoError(t, r.Close())

time.Sleep(100 * time.Millisecond)

require.NoError(t, <-errCh)
_, err = r.pm.Get(5)
require.Error(t, err)

rule, err = rt.Rule(routeID)
require.NoError(t, err)
require.Nil(t, rule)
}

func TestRouterRouteExpiration(t *testing.T) {
client := transport.NewDiscoveryMock()
logStore := transport.InMemoryTransportLogStore()
Expand Down

0 comments on commit bf39234

Please sign in to comment.