Debian Codegraph @

bus/testing/testing_bus.go

raw
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 provides an implementation of bus.Bus and bus.Endpoint
18 // suitable for testing.
19 package testing
20
21 // Here, the bus.Bus implementation.
22
23 import (
24 "gitlab.com/ubports/development/core/lomiri-push-service/bus"
25 "gitlab.com/ubports/development/core/lomiri-push-service/logger"
26 "gitlab.com/ubports/development/core/lomiri-push-service/testing/condition"
27 )
28
29 /*****************************************************************
30 * TestingBus
31 */
32
33 type testingBus struct {
34 endp bus.Endpoint
35 }
36
37 // Build a bus.Bus that takes a condition to determine whether it should work,
38 // as well as a condition and series of return values for the testing
39 // bus.Endpoint it builds.
40 func NewTestingBus(dialTC condition.Interface, callTC condition.Interface, retvals ...interface{}) bus.Bus {
41 return &testingBus{NewTestingEndpoint(dialTC, callTC, retvals...)}
42 }
43
44 // Build a bus.Bus that takes a condition to determine whether it should work,
45 // as well as a condition and a series of lists of return values for the
46 // testing bus.Endpoint it builds.
47 func NewMultiValuedTestingBus(dialTC condition.Interface, callTC condition.Interface, retvalses ...[]interface{}) bus.Bus {
48 return &testingBus{NewMultiValuedTestingEndpoint(dialTC, callTC, retvalses...)}
49 }
50
51 // ensure testingBus implements bus.Interface
52 var _ bus.Bus = &testingBus{}
53
54 /*
55 public methods
56 */
57
58 func (tb *testingBus) Endpoint(info bus.Address, log logger.Logger) bus.Endpoint {
59 return tb.endp
60 }
61
62 func (tb *testingBus) String() string {
63 return "<TestingBus>"
64 }