Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests + automatic test/coverage in travis + docs/readme #16

Merged
merged 34 commits into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5d33a50
added first test
fgschwan Oct 4, 2017
c6c3dfa
added vendor files for base test dependencies
fgschwan Oct 5, 2017
ef24f4e
added gobgp impl test
fgschwan Oct 5, 2017
0d1db2d
Merge branch 'tests'
fgschwan Oct 5, 2017
c29a83b
Remove duplicated package under glide.yaml
Oct 5, 2017
403aee2
extended test to get better coverage
fgschwan Oct 5, 2017
f9108ca
added test and coverage commands to makefile
fgschwan Oct 5, 2017
4f9e46b
Merge remote-tracking branch 'origin/master'
fgschwan Oct 5, 2017
376d4ba
added runnning tests and test coverage for travis
fgschwan Oct 5, 2017
e62c423
added test coverage to readme
fgschwan Oct 5, 2017
9882a47
fixed checkstyle for tests
fgschwan Oct 5, 2017
f0ce5e6
Merge pull request #15 from cgasparini/travis
jozef-slezak Oct 5, 2017
478c6d6
disabled gotypex from checkstyle due to warnings that shouldn't be th…
fgschwan Oct 5, 2017
5d9de6e
added documentation for tests methods
fgschwan Oct 5, 2017
1ec5459
changed testify/assert for gomega in tests
fgschwan Oct 5, 2017
36bbee0
changed testify/assert for gomega in glide files
fgschwan Oct 5, 2017
8a753f7
fixed glide files
fgschwan Oct 5, 2017
36cb7f2
changed testify/assert for gomega in vendor
fgschwan Oct 5, 2017
daed210
Merge branch 'test'
fgschwan Oct 5, 2017
cc8a744
docker folder refactoring
fgschwan Oct 6, 2017
ebefd20
removed not used gobgp configs
fgschwan Oct 6, 2017
3a7699d
removed sudo usage just like it is in other scripts
fgschwan Oct 6, 2017
3534804
made test run look more pretty in console
fgschwan Oct 6, 2017
671a8e4
added quickstart to root readme
fgschwan Oct 6, 2017
f19f05f
simplified removing of docker container
fgschwan Oct 6, 2017
1d8eec9
updated example readme for docker changes
fgschwan Oct 6, 2017
4f9110a
fixed example readme by trying the example step-by-step
fgschwan Oct 6, 2017
baadc6f
added missing readme files
fgschwan Oct 6, 2017
907e75b
added aggregation plugin idea into root readme
fgschwan Oct 6, 2017
1d8881c
removed global variable
fgschwan Oct 9, 2017
879f1f9
added note about creating route reflector in test
fgschwan Oct 9, 2017
b442d41
refactored gobgpplugin test to BDD's given/when/then idiom
fgschwan Oct 9, 2017
3a4015b
fixed testing variable forwarding
fgschwan Oct 9, 2017
1701a77
changed also bgp_api_test to BDD's given/when/test idiom
fgschwan Oct 9, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ before_install:
- sudo add-apt-repository ppa:masterminds/glide -y
- sudo apt-get update -q
- sudo apt-get install glide -y
- go get github.com/mattn/goveralls

script:
- make all

after_success:
- goveralls -coverprofile=/tmp/coverage.out -service=travis-ci
38 changes: 34 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
include Makeroutines.mk

COVER_DIR=/tmp/

# fix sirupsen/Sirupsen problem
define fix_sirupsen_case_sensitivity_problem
@echo "# fixing sirupsen case sensitivity problem, please wait ..."
@-rm -rf vendor/github.com/Sirupsen
@-find ./ -type f -name "*.go" -exec sed -i -e 's/github.com\/Sirupsen\/logrus/github.com\/sirupsen\/logrus/g' {} \;
endef


# run all tests with coverage
define test_cover_only
@echo "# running unit tests with coverage analysis"
@go test -covermode=count -coverprofile=${COVER_DIR}coverage_unit1.out ./bgp
@go test -covermode=count -coverprofile=${COVER_DIR}coverage_unit2.out ./bgp/gobgp
@echo "# merging coverage results"
@gocovmerge ${COVER_DIR}coverage_unit1.out ${COVER_DIR}coverage_unit2.out > ${COVER_DIR}coverage.out
@echo "# coverage data generated into ${COVER_DIR}coverage.out"
@echo "# done"
endef

# build all binaries
build:
@echo "# building"
Expand All @@ -17,6 +31,7 @@ build:
get-tools:
@go get -u -f "github.com/alecthomas/gometalinter"
@gometalinter --install
@go get -u -f "github.com/wadey/gocovmerge"

# install dependencies
install-dep:
Expand All @@ -33,18 +48,32 @@ update-dep:
# run checkstyle
checkstyle:
@echo "# running code analysis"
@gometalinter --vendor --exclude=vendor --deadline 1m --enable-gc --disable=aligncheck --disable=gotype --exclude=mock ./...
@gometalinter --vendor --exclude=vendor --deadline 1m --enable-gc --disable=aligncheck --disable=gotype --disable=gotypex --exclude=mock ./...
@echo "# done"

# run all tests
test:
@echo "# running unit tests"
@go test $$(go list ./... | grep -v /vendor/)

# run tests with coverage report
test-cover:
$(call test_cover_only)

# get coverage percentage in console(without report)
test-cover-without-report:
@echo "# getting test coverage"
@go test -cover $$(go list ./... | grep -v /vendor/)

# build examples
build-examples:
@echo "# building plugin examples"
@cd examples/gobgp_watch_plugin && go build

# run checkstyle
# run examples
run-examples:
@echo "# running examples"
@make build-examples
@echo "# running examples"
@./scripts/run_gobgp_watcher_examples.sh
@echo "# done"

Expand All @@ -68,8 +97,9 @@ all:
@make update-dep
@make checkstyle
@make build
@make test-cover
@make build-examples
@make run-examples
@make clean

.PHONY: build install-dep update-dep checkstyle coverage clean all run-examples
.PHONY: build install-dep update-dep checkstyle coverage clean run-examples test test-cover-without-report
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Ligato BGP Agent
[![Build Status](https://travis-ci.org/ligato/bgp-agent.svg?branch=master)](https://travis-ci.org/ligato/bgp-agent)
[![Coverage Status](https://coveralls.io/repos/github/ligato/bgp-agent/badge.svg?branch=master)](https://coveralls.io/github/ligato/bgp-agent?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/ligato/bgp-agent)](https://goreportcard.com/report/github.com/ligato/bgp-agent)
[![GoDoc](https://godoc.org/github.com/ligato/bgp-agent?status.svg)](https://godoc.org/github.com/ligato/bgp-agent)
[![GitHub license](https://img.shields.io/badge/license-Apache%20license%202.0-blue.svg)](https://github.com/ligato/bgp-agent/blob/master/LICENSE)
Expand All @@ -15,10 +16,22 @@ The architecture of the `Ligato BGP Agent` is shown in the following figure.

Every plugin has its source of BGP information (GoBGP,ExaBGP, Quagga). Communication with the source is vendor specific and therefore also the retrieved BGP information is usually vendor specific. The BGP information is translated into unified format and forwarded to clients. If the source of the BGP information supports listening for updates, plugin forwards to its clients also informations from updates.

Clients can register directly to plugins, choosing what information they want to consume. Each plugin can expose different set of BGP informations depending at capabilities of their source(GoBGP,ExaBGP,...) or plugin's client target(different plugins for different AFI/SAFI). But each type of BGP information, no matter from which plugin it came, has the same unified format. Also plugins can be clients to other plugins.
Clients can register directly to plugins, choosing what information they want to consume. Each plugin can expose different set of BGP informations depending at capabilities of their source(GoBGP,ExaBGP,...) or plugin's client target(different plugins for different AFI/SAFI). But each type of BGP information, no matter from which plugin it came, has the same unified format.

Plugins can be clients of other plugins too. This means that the architecture is quite flexible for the future usage. Different plugins can provide different types of BGP information/from different sources and can be kept separate as building stones for (hierarchy of) aggregator plugins. The aggregator plugin uses other plugins to retrieve needed information for its own registered clients. The aggregator plugins can for example provide information for one AFI/SAFI across multiple sources. This can be usefull if one source can provide all needed information or such source exists but can't be used for whatever reason. There are many possibilities how to combine plugins together to satisfy specific use cases.

Currently, only [GoBGP plugin](bgp/gobgp/README.md) that exposes IPv4 reachable routes is available. ExaBGP,Quagga plugins are not implemented.

## Quickstart
For a quick start with the BGP Agent, you can use makefile and start examples
```
make run-examples
```
The command pulls needed docker images from [Dockerhub](https://hub.docker.com/r/ligato/gobgp-for-rr/),
setups networking, builds the examples, runs them, validates their output and cleans after them.

You can check in the command output the most basic test, the [gobgp_watch_plugin](https://github.com/fgschwan/bgp-agent/tree/master/examples/gobgp_watch_plugin).

## Documentation
GoDoc can be browsed [online](https://godoc.org/github.com/ligato/bgp-agent).

Expand Down
42 changes: 42 additions & 0 deletions bgp/bgp_api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2017 Pantheon technologies s.r.o.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package bgp

import (
"github.com/ligato/cn-infra/logging/logrus"
. "github.com/onsi/gomega"
"net"
"reflect"
"testing"
)

// TestToChan tests ability of ToChan(...) function to create wrapping function that wraps given channel and forwards
// all ReachableIPRoute data (given to the wrapping function by parameter) to the channel inside.
// Test doesn't check logging capabilities of wrapping function.
func TestToChan(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain in comment what is the intent of this test

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment added

// prepare of tested instances/helper instances
RegisterTestingT(t)
channel := make(chan ReachableIPRoute, 1)
wrappingFunc := ToChan(channel, logrus.DefaultLogger())

// testing ToChan's returned function
Expect(channel).To(BeEmpty())
sent := ReachableIPRoute{As: 1, Prefix: "1.2.3.4/32", Nexthop: net.IPv4(192, 168, 1, 1)}
wrappingFunc(&sent)
Expect(channel).ToNot(BeEmpty())
received := <-channel
reflect.DeepEqual(sent, received)
Expect(channel).To(BeEmpty())
}
Loading