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

Conversation

fgschwan
Copy link
Collaborator

@fgschwan fgschwan commented Oct 5, 2017

No description provided.


import (
"github.com/ligato/cn-infra/logging/logrus"
"github.com/stretchr/testify/assert"
Copy link
Contributor

Choose a reason for hiding this comment

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

please use gomega to unify assertions all over the ligato

"testing"
)

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

goBGPPlugin := createGoBGPPlugin(serverConf)

// watch -> start lifecycle of gobgp plugin -> send path to Route reflector -> check receiving on other end
watchRegistration, registrationErr := goBGPPlugin.WatchIPRoutes("TestWatcher", bgp.ToChan(channel, logroot.StandardLogger()))
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to use ToChan in here is it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Basically no need to use callback either.
I chose channel because:

  1. I had some methods (outdated test from Claudio) that used channel
  2. for callback i had to do some struct that would record what came using callback. Channel is build in, so one struct less.


var flavor = &local.FlavorLocal{}

func TestGoBGPPluginInfoPassing(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.

Consider having: Given/When/Then test steps to do the test scenario readable.

Take a look at https://github.com/ligato/sfc-controller/pull/1/files#diff-b2ae6240742894fb8ffcd1d9406f9ad3R33 it it helps you....

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

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 5d9de6e on fgschwan:master into ** on ligato:master**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling daed210 on fgschwan:master into ** on ligato:master**.

@fgschwan fgschwan changed the title Added tests + automatic test/coverage in travis Added tests + automatic test/coverage in travis + docs/readme Oct 6, 2017
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 907e75b on fgschwan:master into ** on ligato:master**.

timeoutForNotReceiving = 5 * time.Second
)

var flavor = &local.FlavorLocal{}
Copy link
Contributor

Choose a reason for hiding this comment

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

let's not use global variables other than test data or test configuration

Expect(watchRegistration).NotTo(BeNil(), "WatchRegistration must be non-nil to be able to close registration later")
lifecycleCloseChannel := startPluginLifecycle(goBGPPlugin, assertCorrectLifecycleEnd(&lifecycleWG))
Expect(waitForSessionEstablishment(routeReflector)).To(BeNil(), "Session not established within timeout")
Expect(addNewRoute(routeReflector, prefix1, nextHop1, length)).To(BeNil(), "Can't add new route")
Copy link
Contributor

Choose a reason for hiding this comment

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

When.addNewRoute()
Then.assertThatChannelReceivesCorrectRoute

var lifecycleWG sync.WaitGroup

// create components
routeReflector, err := createAndStartRouteReflector(routeReflectorConf)
Copy link
Contributor

Choose a reason for hiding this comment

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

Given.RouteReflectorGoBGP

(extract all intermediate assertions away from test scenario to make it readable)

watchRegistration, registrationErr := goBGPPlugin.WatchIPRoutes("TestWatcher", bgp.ToChan(channel, logroot.StandardLogger()))
Expect(registrationErr).To(BeNil(), "Can't properly register to watch IP routes")
Expect(watchRegistration).NotTo(BeNil(), "WatchRegistration must be non-nil to be able to close registration later")
lifecycleCloseChannel := startPluginLifecycle(goBGPPlugin, assertCorrectLifecycleEnd(&lifecycleWG))
Copy link
Contributor

Choose a reason for hiding this comment

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

Given.AgentPluginGoBGP

(extract all intermediate assertions away from test scenario to make it readable)


// TestGoBGPPluginInfoPassing tests gobgp plugin for the ability of retrieving of ReachableIPRoutes using BGP protocol and passing this information to its registered watchers.
// Test is also testing the ability of watch unregistering.
func TestGoBGPPluginInfoPassing(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.

In general:

  1. emphasize that you are starting dedicated GoBGP Route Reflector (because once somebody wants to add yet another test there will be concurrency problem - two tests would want to start GoBGP Route Reflector)
  2. Extract intermediate assertions of return values away from scenario (starting new thing - checking not error, watch registration checking not error)
  3. Move test data, test configuration, test helper functions to dedicated file

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 1701a77 on fgschwan:master into ** on ligato:master**.

@jozef-slezak jozef-slezak merged commit 1424035 into ligato:master Oct 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants