Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package distributor | |
| 6 | |
| 7 import ( | |
| 8 "fmt" | |
| 9 | |
| 10 "github.com/luci/luci-go/appengine/tumble" | |
| 11 "github.com/luci/luci-go/common/api/dm/service/v1" | |
| 12 "golang.org/x/net/context" | |
| 13 ) | |
| 14 | |
| 15 type testRegistry struct { | |
| 16 finishExecutionImpl FinishExecutionFn | |
| 17 data map[string]D | |
| 18 } | |
| 19 | |
| 20 var _ Registry = (*testRegistry)(nil) | |
|
dnj (Google)
2016/06/09 18:00:56
nit: this isn't necessary, since NewTestingRegistr
iannucci
2016/06/15 00:46:01
I like putting this near every type definition so
| |
| 21 | |
| 22 // NewTestingRegistry returns a new testing registry. | |
| 23 // | |
| 24 // The mocks dictionary maps from cfgName to a mock implementation of the | |
| 25 // distributor. | |
| 26 func NewTestingRegistry(mocks map[string]D, fFn FinishExecutionFn) Registry { | |
|
iannucci
2016/06/08 02:54:24
this evades luci-config/pubsub in tests.
| |
| 27 return &testRegistry{fFn, mocks} | |
| 28 } | |
| 29 | |
| 30 func (t *testRegistry) FinishExecution(c context.Context, eid *dm.Execution_ID, rslt *TaskResult) ([]tumble.Mutation, error) { | |
| 31 return t.finishExecutionImpl(c, eid, rslt) | |
| 32 } | |
| 33 | |
| 34 func (t *testRegistry) MakeDistributor(_ context.Context, cfgName string) (D, st ring, error) { | |
| 35 ret, ok := t.data[cfgName] | |
| 36 if !ok { | |
| 37 return nil, "", fmt.Errorf("unknown distributor configuration: % q", cfgName) | |
| 38 } | |
| 39 return ret, "testing", nil | |
| 40 } | |
| OLD | NEW |