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) |
| 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 { |
| 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 |