mirror of
https://github.com/bgp/stayrtr.git
synced 2024-05-06 15:54:54 +00:00
initial client test set up
This commit is contained in:
1
go.mod
1
go.mod
@ -3,6 +3,7 @@ module github.com/bgp/stayrtr
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/google/go-cmp v0.5.6 // indirect
|
||||
github.com/prometheus/client_golang v0.9.2
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/stretchr/testify v1.2.2
|
||||
|
3
go.sum
3
go.sum
@ -4,6 +4,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
|
||||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
@ -34,3 +36,4 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
60
lib/client_test.go
Normal file
60
lib/client_test.go
Normal file
@ -0,0 +1,60 @@
|
||||
package rtrlib
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/bgp/stayrtr/prefixfile"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
var (
|
||||
Serial = uint32(0)
|
||||
Session = uint16(0)
|
||||
InitSerial = false
|
||||
)
|
||||
|
||||
type TestClient struct {
|
||||
Data prefixfile.VRPList
|
||||
|
||||
InitSerial bool
|
||||
Serial uint32
|
||||
SessionID uint16
|
||||
}
|
||||
|
||||
func getClientConguration() ClientConfiguration {
|
||||
return ClientConfiguration{
|
||||
ProtocolVersion: 1,
|
||||
RefreshInterval: 10,
|
||||
RetryInterval: 15,
|
||||
ExpireInterval: 20,
|
||||
}
|
||||
}
|
||||
func getClient() *TestClient {
|
||||
return &TestClient{
|
||||
Data: prefixfile.VRPList{
|
||||
Metadata: prefixfile.MetaData{},
|
||||
Data: make([]prefixfile.VRPJson, 0),
|
||||
},
|
||||
InitSerial: InitSerial,
|
||||
Serial: Serial,
|
||||
SessionID: Session,
|
||||
}
|
||||
}
|
||||
|
||||
func (tc *TestClient) HandlePDU(cs *ClientSession, pdu PDU) {}
|
||||
|
||||
func (tc *TestClient) ClientConnected(cs *ClientSession) {}
|
||||
|
||||
func (tc *TestClient) ClientDisconnected(cs *ClientSession) {}
|
||||
|
||||
func TestSendResetQuery(t *testing.T) {
|
||||
cs := NewClientSession(getClientConguration(), getClient())
|
||||
cs.SendResetQuery()
|
||||
c := <-cs.transmits
|
||||
|
||||
reset := &PDUResetQuery{PROTOCOL_VERSION_1}
|
||||
|
||||
if !cmp.Equal(c, reset) {
|
||||
t.Errorf("Wanted a PDU Reset Query, but got (%+v)", c)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user