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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: dm/appengine/distributor/test_registry.go
diff --git a/dm/appengine/distributor/test_registry.go b/dm/appengine/distributor/test_registry.go
index ce39c3b51d1f0744694883c49407ce105ca5520c..b060c655afb4a4c6ffdbdb2c672557e7437f6f70 100644
--- a/dm/appengine/distributor/test_registry.go
+++ b/dm/appengine/distributor/test_registry.go
@@ -12,9 +12,13 @@ import (
"golang.org/x/net/context"
)
+type TestFactoryFn func(context.Context, *Config) D
+
+type TestFactoryMap map[string]TestFactoryFn
+
type testRegistry struct {
finishExecutionImpl FinishExecutionFn
- data map[string]D
+ data TestFactoryMap
}
var _ Registry = (*testRegistry)(nil)
@@ -23,7 +27,7 @@ var _ Registry = (*testRegistry)(nil)
//
// The mocks dictionary maps from cfgName to a mock implementation of the
// distributor.
-func NewTestingRegistry(mocks map[string]D, fFn FinishExecutionFn) Registry {
+func NewTestingRegistry(mocks TestFactoryMap, fFn FinishExecutionFn) Registry {
return &testRegistry{fFn, mocks}
}
@@ -31,10 +35,14 @@ func (t *testRegistry) FinishExecution(c context.Context, eid *dm.Execution_ID,
return t.finishExecutionImpl(c, eid, rslt)
}
-func (t *testRegistry) MakeDistributor(_ context.Context, cfgName string) (D, string, error) {
+func (t *testRegistry) MakeDistributor(c context.Context, cfgName string) (D, string, error) {
ret, ok := t.data[cfgName]
if !ok {
return nil, "", fmt.Errorf("unknown distributor configuration: %q", cfgName)
}
- return ret, "testing", nil
+ return ret(c, &Config{
+ DMHost: "test-dm-host.example.com",
+ Version: "test-version",
+ Name: cfgName,
+ }), "testing", nil
}

Powered by Google App Engine
This is Rietveld 408576698