| 1 |
/* |
| 2 |
Copyright 2013-2014 Canonical Ltd. |
| 3 |
|
| 4 |
This program is free software: you can redistribute it and/or modify it |
| 5 |
under the terms of the GNU General Public License version 3, as published |
| 6 |
by the Free Software Foundation. |
| 7 |
|
| 8 |
This program is distributed in the hope that it will be useful, but |
| 9 |
WITHOUT ANY WARRANTY; without even the implied warranties of |
| 10 |
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
| 11 |
PURPOSE. See the GNU General Public License for more details. |
| 12 |
|
| 13 |
You should have received a copy of the GNU General Public License along |
| 14 |
with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
package testing |
| 18 |
|
| 19 |
import ( |
| 20 |
. "gopkg.in/check.v1" |
| 21 |
"gitlab.com/ubports/development/core/lomiri-push-service/bus" |
| 22 |
"gitlab.com/ubports/development/core/lomiri-push-service/testing/condition" |
| 23 |
"testing" |
| 24 |
) |
| 25 |
|
| 26 |
// hook up gocheck |
| 27 |
func BusTest(t *testing.T) { TestingT(t) } |
| 28 |
|
| 29 |
type TestingBusSuite struct{} |
| 30 |
|
| 31 |
var _ = Suite(&TestingBusSuite{}) |
| 32 |
|
| 33 |
// Test Endpoint() on a working bus returns an endpoint that looks right |
| 34 |
func (s *TestingBusSuite) TestEndpointWorks(c *C) { |
| 35 |
addr := bus.Address{"", "", ""} |
| 36 |
tb := NewTestingBus(condition.Work(true), condition.Work(false), 42, 42, 42) |
| 37 |
endp := tb.Endpoint(addr, nil) |
| 38 |
err := endp.Dial() |
| 39 |
c.Check(err, IsNil) |
| 40 |
c.Assert(endp, FitsTypeOf, &testingEndpoint{}) |
| 41 |
c.Check(endp.(*testingEndpoint).callCond.OK(), Equals, false) |
| 42 |
c.Check(endp.(*testingEndpoint).retvals, HasLen, 3) |
| 43 |
} |
| 44 |
|
| 45 |
// Test Endpoint() on a working "multi-valued" bus returns an endpoint that looks right |
| 46 |
func (s *TestingBusSuite) TestEndpointMultiValued(c *C) { |
| 47 |
addr := bus.Address{"", "", ""} |
| 48 |
tb := NewMultiValuedTestingBus(condition.Work(true), condition.Work(true), |
| 49 |
[]interface{}{42, 17}, |
| 50 |
[]interface{}{42, 17, 13}, |
| 51 |
[]interface{}{42}, |
| 52 |
) |
| 53 |
endpp := tb.Endpoint(addr, nil) |
| 54 |
err := endpp.Dial() |
| 55 |
c.Check(err, IsNil) |
| 56 |
endp, ok := endpp.(*testingEndpoint) |
| 57 |
c.Assert(ok, Equals, true) |
| 58 |
c.Check(endp.callCond.OK(), Equals, true) |
| 59 |
c.Assert(endp.retvals, HasLen, 3) |
| 60 |
c.Check(endp.retvals[0], HasLen, 2) |
| 61 |
c.Check(endp.retvals[1], HasLen, 3) |
| 62 |
c.Check(endp.retvals[2], HasLen, 1) |
| 63 |
} |
| 64 |
|
| 65 |
// Test TestingBus stringifies sanely |
| 66 |
func (s *TestingBusSuite) TestStringifyBus(c *C) { |
| 67 |
tb := NewTestingBus(nil, nil) |
| 68 |
c.Check(tb.String(), Matches, ".*TestingBus.*") |
| 69 |
} |