Skip to content

Commit ffd6721

Browse files
committed
add unit-test
Signed-off-by: Angelo De Caro <adc@zurich.ibm.com>
1 parent bcad6ca commit ffd6721

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

platform/view/services/view/manager_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"time"
1414

1515
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils"
16+
"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
1617
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/metrics/disabled"
1718
view2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/view"
1819
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/view/mock"
@@ -50,6 +51,18 @@ func (a DummyView) Call(context view.Context) (interface{}, error) {
5051
return nil, nil
5152
}
5253

54+
type ContextKey = string
55+
56+
type DummyViewContextCheck struct{}
57+
58+
func (a DummyViewContextCheck) Call(ctx view.Context) (interface{}, error) {
59+
v, ok := ctx.Context().Value(ContextKey("test")).(string)
60+
if !ok {
61+
return nil, errors.Errorf("context value %s not found", ContextKey("test"))
62+
}
63+
return v, nil
64+
}
65+
5366
type DummyFactory struct{}
5467

5568
func (d *DummyFactory) NewView(in []byte) (view.View, error) {
@@ -97,6 +110,7 @@ func TestManagerRace(t *testing.T) {
97110
go registerFactory(t, wg, manager)
98111
go newView(t, wg, manager)
99112
go callView(t, wg, manager)
113+
go callViewWithAugmentedContext(t, wg, manager)
100114
go getContext(t, wg, manager)
101115
go initiateView(t, wg, manager)
102116
go start(t, wg, manager, ctx)
@@ -153,6 +167,15 @@ func callView(t *testing.T, wg *sync.WaitGroup, m Manager) {
153167
assert.NoError(t, err)
154168
}
155169

170+
func callViewWithAugmentedContext(t *testing.T, wg *sync.WaitGroup, m Manager) {
171+
ctx := context.Background()
172+
ctx = context.WithValue(ctx, ContextKey("test"), "pineapple")
173+
v, err := m.InitiateView(&DummyViewContextCheck{}, ctx)
174+
wg.Done()
175+
assert.NoError(t, err)
176+
assert.Equal(t, "pineapple", v)
177+
}
178+
156179
func newView(t *testing.T, wg *sync.WaitGroup, m Manager) {
157180
_, err := m.NewView(utils.GenerateUUID(), nil)
158181
wg.Done()

0 commit comments

Comments
 (0)