Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: dm/appengine/distributor/test_registry.go

Issue 2347973003: Refactor distributor API so that methods always get the Quest_Desc too. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package distributor 5 package distributor
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 9
10 "github.com/luci/luci-go/dm/api/service/v1" 10 "github.com/luci/luci-go/dm/api/service/v1"
11 "github.com/luci/luci-go/tumble" 11 "github.com/luci/luci-go/tumble"
12 "golang.org/x/net/context" 12 "golang.org/x/net/context"
13 ) 13 )
14 14
15 type TestFactoryFn func(context.Context, *Config) D
16
17 type TestFactoryMap map[string]TestFactoryFn
18
15 type testRegistry struct { 19 type testRegistry struct {
16 finishExecutionImpl FinishExecutionFn 20 finishExecutionImpl FinishExecutionFn
17 » data map[string]D 21 » data TestFactoryMap
18 } 22 }
19 23
20 var _ Registry = (*testRegistry)(nil) 24 var _ Registry = (*testRegistry)(nil)
21 25
22 // NewTestingRegistry returns a new testing registry. 26 // NewTestingRegistry returns a new testing registry.
23 // 27 //
24 // The mocks dictionary maps from cfgName to a mock implementation of the 28 // The mocks dictionary maps from cfgName to a mock implementation of the
25 // distributor. 29 // distributor.
26 func NewTestingRegistry(mocks map[string]D, fFn FinishExecutionFn) Registry { 30 func NewTestingRegistry(mocks TestFactoryMap, fFn FinishExecutionFn) Registry {
27 return &testRegistry{fFn, mocks} 31 return &testRegistry{fFn, mocks}
28 } 32 }
29 33
30 func (t *testRegistry) FinishExecution(c context.Context, eid *dm.Execution_ID, rslt *dm.Result) ([]tumble.Mutation, error) { 34 func (t *testRegistry) FinishExecution(c context.Context, eid *dm.Execution_ID, rslt *dm.Result) ([]tumble.Mutation, error) {
31 return t.finishExecutionImpl(c, eid, rslt) 35 return t.finishExecutionImpl(c, eid, rslt)
32 } 36 }
33 37
34 func (t *testRegistry) MakeDistributor(_ context.Context, cfgName string) (D, st ring, error) { 38 func (t *testRegistry) MakeDistributor(c context.Context, cfgName string) (D, st ring, error) {
35 ret, ok := t.data[cfgName] 39 ret, ok := t.data[cfgName]
36 if !ok { 40 if !ok {
37 return nil, "", fmt.Errorf("unknown distributor configuration: % q", cfgName) 41 return nil, "", fmt.Errorf("unknown distributor configuration: % q", cfgName)
38 } 42 }
39 » return ret, "testing", nil 43 » return ret(c, &Config{
44 » » DMHost: "test-dm-host.example.com",
45 » » Version: "test-version",
46 » » Name: cfgName,
47 » }), "testing", nil
40 } 48 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698