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

Unified Diff: appengine/cmd/dm/distributor/test_registry.go

Issue 1537883002: Initial distributor implementation (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: self review Created 4 years, 6 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: appengine/cmd/dm/distributor/test_registry.go
diff --git a/appengine/cmd/dm/distributor/test_registry.go b/appengine/cmd/dm/distributor/test_registry.go
new file mode 100644
index 0000000000000000000000000000000000000000..31852fb7c6b0b7c49e4b071b48e7fa3118f6387e
--- /dev/null
+++ b/appengine/cmd/dm/distributor/test_registry.go
@@ -0,0 +1,40 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package distributor
+
+import (
+ "fmt"
+
+ "github.com/luci/luci-go/appengine/tumble"
+ "github.com/luci/luci-go/common/api/dm/service/v1"
+ "golang.org/x/net/context"
+)
+
+type testRegistry struct {
+ finishExecutionImpl FinishExecutionFn
+ data map[string]D
+}
+
+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
+
+// NewTestingRegistry returns a new testing registry.
+//
+// The mocks dictionary maps from cfgName to a mock implementation of the
+// distributor.
+func NewTestingRegistry(mocks map[string]D, fFn FinishExecutionFn) Registry {
iannucci 2016/06/08 02:54:24 this evades luci-config/pubsub in tests.
+ return &testRegistry{fFn, mocks}
+}
+
+func (t *testRegistry) FinishExecution(c context.Context, eid *dm.Execution_ID, rslt *TaskResult) ([]tumble.Mutation, error) {
+ return t.finishExecutionImpl(c, eid, rslt)
+}
+
+func (t *testRegistry) MakeDistributor(_ 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
+}

Powered by Google App Engine
This is Rietveld 408576698