| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package coordinatorTest | 5 package coordinatorTest |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "fmt" | 9 "fmt" |
| 10 "time" |
| 10 | 11 |
| 11 "github.com/golang/protobuf/proto" | 12 "github.com/golang/protobuf/proto" |
| 12 ds "github.com/luci/gae/service/datastore" | 13 ds "github.com/luci/gae/service/datastore" |
| 13 "github.com/luci/luci-go/appengine/logdog/coordinator" | 14 "github.com/luci/luci-go/appengine/logdog/coordinator" |
| 14 "github.com/luci/luci-go/common/clock" | 15 "github.com/luci/luci-go/common/clock" |
| 15 "github.com/luci/luci-go/common/config" | 16 "github.com/luci/luci-go/common/config" |
| 16 "github.com/luci/luci-go/common/logdog/types" | 17 "github.com/luci/luci-go/common/logdog/types" |
| 17 "github.com/luci/luci-go/common/proto/google" | 18 "github.com/luci/luci-go/common/proto/google" |
| 18 "github.com/luci/luci-go/common/proto/logdog/logpb" | 19 "github.com/luci/luci-go/common/proto/logdog/logpb" |
| 19 "golang.org/x/net/context" | 20 "golang.org/x/net/context" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 39 // Prefix is the Coordinator LogStreamState entity. | 40 // Prefix is the Coordinator LogStreamState entity. |
| 40 State *coordinator.LogStreamState | 41 State *coordinator.LogStreamState |
| 41 // Prefix is the Coordinator LogStream entity. | 42 // Prefix is the Coordinator LogStream entity. |
| 42 Stream *coordinator.LogStream | 43 Stream *coordinator.LogStream |
| 43 } | 44 } |
| 44 | 45 |
| 45 // MakeStream builds a new TestStream with the supplied parameters. | 46 // MakeStream builds a new TestStream with the supplied parameters. |
| 46 func MakeStream(c context.Context, project config.ProjectName, path types.Stream
Path) *TestStream { | 47 func MakeStream(c context.Context, project config.ProjectName, path types.Stream
Path) *TestStream { |
| 47 prefix, name := path.Split() | 48 prefix, name := path.Split() |
| 48 | 49 |
| 49 » now := ds.RoundTime(clock.Now(c)).UTC() | 50 » now := clock.Now(c).UTC() |
| 50 secret := TestSecret() | 51 secret := TestSecret() |
| 51 | 52 |
| 52 ts := TestStream{ | 53 ts := TestStream{ |
| 53 Project: project, | 54 Project: project, |
| 55 Prefix: &coordinator.LogPrefix{ |
| 56 ID: "", // Filled in by Reload. |
| 57 Created: ds.RoundTime(now), |
| 58 Prefix: "", // Filled in by Reload. |
| 59 Source: []string{"test suite"}, |
| 60 Secret: secret, |
| 61 }, |
| 54 Desc: &logpb.LogStreamDescriptor{ | 62 Desc: &logpb.LogStreamDescriptor{ |
| 55 Prefix: string(prefix), | 63 Prefix: string(prefix), |
| 56 Name: string(name), | 64 Name: string(name), |
| 57 StreamType: logpb.StreamType_TEXT, | 65 StreamType: logpb.StreamType_TEXT, |
| 58 ContentType: "application/text", | 66 ContentType: "application/text", |
| 59 Timestamp: google.NewTimestamp(now), | 67 Timestamp: google.NewTimestamp(now), |
| 60 }, | 68 }, |
| 61 Prefix: &coordinator.LogPrefix{ | |
| 62 Created: ds.RoundTime(now), | |
| 63 Secret: secret, | |
| 64 }, | |
| 65 State: &coordinator.LogStreamState{ | 69 State: &coordinator.LogStreamState{ |
| 66 » » » Created: now, | 70 » » » Parent: nil, // Filled in by Reload. |
| 71 » » » Created: ds.RoundTime(now), |
| 72 » » » Updated: time.Time{}, // Filled in by Reload. |
| 67 Secret: secret, | 73 Secret: secret, |
| 68 TerminalIndex: -1, | 74 TerminalIndex: -1, |
| 69 }, | 75 }, |
| 70 Stream: &coordinator.LogStream{ | 76 Stream: &coordinator.LogStream{ |
| 77 ID: "", // Filled in by Reload. |
| 71 ProtoVersion: logpb.Version, | 78 ProtoVersion: logpb.Version, |
| 72 » » » Created: now, | 79 » » » Created: ds.RoundTime(now), |
| 80 » » » // Descriptor-derived fields filled in by Reload. |
| 73 }, | 81 }, |
| 74 } | 82 } |
| 75 ts.Reload(c) | 83 ts.Reload(c) |
| 76 return &ts | 84 return &ts |
| 77 } | 85 } |
| 78 | 86 |
| 79 // Reload loads derived fields from their base fields. | 87 // Reload loads derived fields from their base fields. |
| 80 func (ts *TestStream) Reload(c context.Context) { | 88 func (ts *TestStream) Reload(c context.Context) { |
| 81 ts.Path = ts.Desc.Path() | 89 ts.Path = ts.Desc.Path() |
| 82 | 90 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } | 167 } |
| 160 } | 168 } |
| 161 return &le | 169 return &le |
| 162 } | 170 } |
| 163 | 171 |
| 164 // WithProjectNamespace runs f in proj's namespace, bypassing authentication | 172 // WithProjectNamespace runs f in proj's namespace, bypassing authentication |
| 165 // checks. | 173 // checks. |
| 166 func (ts *TestStream) WithProjectNamespace(c context.Context, f func(context.Con
text)) { | 174 func (ts *TestStream) WithProjectNamespace(c context.Context, f func(context.Con
text)) { |
| 167 WithProjectNamespace(c, ts.Project, f) | 175 WithProjectNamespace(c, ts.Project, f) |
| 168 } | 176 } |
| OLD | NEW |