From fe8a0f46323e56a8dde9ab2f02e0b4280571727b Mon Sep 17 00:00:00 2001 From: Darren O'Connor Date: Sun, 24 Oct 2021 15:26:47 -0400 Subject: [PATCH] initial client test set up --- go.mod | 1 + go.sum | 3 +++ lib/client_test.go | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 lib/client_test.go diff --git a/go.mod b/go.mod index fd32366..39b7177 100644 --- a/go.mod +++ b/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 diff --git a/go.sum b/go.sum index 2510aac..fabf8ac 100644 --- a/go.sum +++ b/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= diff --git a/lib/client_test.go b/lib/client_test.go new file mode 100644 index 0000000..ce4e73c --- /dev/null +++ b/lib/client_test.go @@ -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) + } +}