-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from fgschwan/master
Added tests + automatic test/coverage in travis + docs/readme
- Loading branch information
Showing
213 changed files
with
12,886 additions
and
10,687 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// 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_test contains tests for API helper functions | ||
package bgp_test | ||
|
||
import ( | ||
"github.com/ligato/bgp-agent/bgp" | ||
"github.com/ligato/cn-infra/logging/logrus" | ||
. "github.com/onsi/gomega" | ||
"net" | ||
"testing" | ||
) | ||
|
||
// TestHelper allows tests to be written in given/when/then idiom of BDD | ||
type TestHelper struct { | ||
vars *Variables | ||
Given Given | ||
When When | ||
Then Then | ||
golangTesting *testing.T | ||
} | ||
|
||
// Variables is container of variables that should be accessible from every BDD component | ||
type Variables struct { | ||
golangT *testing.T | ||
channel chan bgp.ReachableIPRoute | ||
wrappingFunc func(info *bgp.ReachableIPRoute) | ||
sentRoute bgp.ReachableIPRoute | ||
} | ||
|
||
// Given is composition of multiple test step methods (see BDD Given keyword) | ||
type Given struct { | ||
vars *Variables | ||
} | ||
|
||
// When is composition of multiple test step methods (see BDD When keyword) | ||
type When struct { | ||
vars *Variables | ||
} | ||
|
||
// Then is composition of multiple test step methods (see BDD Then keyword) | ||
type Then struct { | ||
vars *Variables | ||
} | ||
|
||
// DefaultSetup setups needed variables and ensures that these variables are accessible from all test BDD components (given, when, then) | ||
func (t *TestHelper) DefaultSetup() { | ||
// creating and linking variables to test parts | ||
t.vars = &Variables{} | ||
t.Given.vars = t.vars | ||
t.When.vars = t.vars | ||
t.Then.vars = t.vars | ||
|
||
// registering gomega | ||
RegisterTestingT(t.vars.golangT) | ||
|
||
// initialize used channel | ||
t.vars.channel = make(chan bgp.ReachableIPRoute, 1) | ||
} | ||
|
||
func (g *Given) WrappingFuncAsToChanResult() { | ||
g.vars.wrappingFunc = bgp.ToChan(g.vars.channel, logrus.DefaultLogger()) | ||
} | ||
|
||
func (w *When) SentRouteToWrappingFunc() { | ||
w.vars.sentRoute = bgp.ReachableIPRoute{As: 1, Prefix: "1.2.3.4/32", Nexthop: net.IPv4(192, 168, 1, 1)} | ||
w.vars.wrappingFunc(&w.vars.sentRoute) | ||
} | ||
|
||
func (t *Then) ChannelReceiveIt() { | ||
Expect(t.vars.channel).ToNot(BeEmpty()) | ||
received := <-t.vars.channel | ||
Expect(received).To(Equal(t.vars.sentRoute)) | ||
Expect(t.vars.channel).To(BeEmpty()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// 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_test contains tests for API helper functions | ||
package bgp_test | ||
|
||
import ( | ||
"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(x *testing.T) { | ||
t := TestHelper{golangTesting: x} | ||
t.DefaultSetup() | ||
|
||
t.Given.WrappingFuncAsToChanResult() | ||
t.When.SentRouteToWrappingFunc() | ||
t.Then.ChannelReceiveIt() | ||
} |
Oops, something went wrong.