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

Side by Side Diff: milo/appengine/swarming/buildinfo_test.go

Issue 2695383002: milo: Enable Swarming LogDog log loading. (Closed)
Patch Set: Comments, fix links. Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The LUCI Authors. All rights reserved. 1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package swarming 5 package swarming
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "testing" 9 "testing"
10 10
11 swarming "github.com/luci/luci-go/common/api/swarming/swarming/v1" 11 swarming "github.com/luci/luci-go/common/api/swarming/swarming/v1"
12 miloProto "github.com/luci/luci-go/common/proto/milo" 12 miloProto "github.com/luci/luci-go/common/proto/milo"
13 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/logs/v1" 13 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/logs/v1"
14 "github.com/luci/luci-go/logdog/api/logpb"
15 "github.com/luci/luci-go/logdog/client/coordinator" 14 "github.com/luci/luci-go/logdog/client/coordinator"
16 milo "github.com/luci/luci-go/milo/api/proto" 15 milo "github.com/luci/luci-go/milo/api/proto"
17 16
18 "github.com/luci/gae/impl/memory" 17 "github.com/luci/gae/impl/memory"
19 18
20 "github.com/golang/protobuf/proto"
21 "golang.org/x/net/context" 19 "golang.org/x/net/context"
22 "google.golang.org/grpc"
23 20
24 . "github.com/luci/luci-go/common/testing/assertions" 21 . "github.com/luci/luci-go/common/testing/assertions"
25 . "github.com/smartystreets/goconvey/convey" 22 . "github.com/smartystreets/goconvey/convey"
26 ) 23 )
27 24
28 // testLogDogClient is a minimal functional LogsClient implementation.
29 //
30 // It retains its latest input parameter and returns its configured err (if not
31 // nil) or resp.
32 type testLogDogClient struct {
33 logdog.LogsClient
34
35 req interface{}
36 resp interface{}
37 err error
38 }
39
40 func (tc *testLogDogClient) Tail(ctx context.Context, in *logdog.TailRequest, op ts ...grpc.CallOption) (
41 *logdog.GetResponse, error) {
42
43 tc.req = in
44 if tc.err != nil {
45 return nil, tc.err
46 }
47 return tc.resp.(*logdog.GetResponse), nil
48 }
49
50 type testSwarmingService struct { 25 type testSwarmingService struct {
51 swarmingService 26 swarmingService
52 27
53 host string 28 host string
54 req swarming.SwarmingRpcsTaskRequest 29 req swarming.SwarmingRpcsTaskRequest
55 res swarming.SwarmingRpcsTaskResult 30 res swarming.SwarmingRpcsTaskResult
56 } 31 }
57 32
58 func (sf *testSwarmingService) getHost() string { return sf.host } 33 func (sf *testSwarmingService) getHost() string { return sf.host }
59 34
60 func (sf *testSwarmingService) getSwarmingResult(c context.Context, taskID strin g) ( 35 func (sf *testSwarmingService) getSwarmingResult(c context.Context, taskID strin g) (
61 *swarming.SwarmingRpcsTaskResult, error) { 36 *swarming.SwarmingRpcsTaskResult, error) {
62 37
63 return &sf.res, nil 38 return &sf.res, nil
64 } 39 }
65 40
66 func (sf *testSwarmingService) getSwarmingRequest(c context.Context, taskID stri ng) ( 41 func (sf *testSwarmingService) getSwarmingRequest(c context.Context, taskID stri ng) (
67 *swarming.SwarmingRpcsTaskRequest, error) { 42 *swarming.SwarmingRpcsTaskRequest, error) {
68 43
69 return &sf.req, nil 44 return &sf.req, nil
70 } 45 }
71 46
72 func datagramGetResponse(project, prefix string, msg proto.Message) *logdog.GetR esponse {
73 data, err := proto.Marshal(msg)
74 if err != nil {
75 panic(err)
76 }
77 return &logdog.GetResponse{
78 Project: project,
79 Desc: &logpb.LogStreamDescriptor{
80 Prefix: prefix,
81 ContentType: miloProto.ContentTypeAnnotations,
82 StreamType: logpb.StreamType_DATAGRAM,
83 },
84 State: &logdog.LogStreamState{},
85 Logs: []*logpb.LogEntry{
86 {
87 Content: &logpb.LogEntry_Datagram{
88 Datagram: &logpb.Datagram{
89 Data: data,
90 },
91 },
92 },
93 },
94 }
95 }
96
97 func TestBuildInfo(t *testing.T) { 47 func TestBuildInfo(t *testing.T) {
98 t.Parallel() 48 t.Parallel()
99 49
100 Convey("A testing BuildInfoProvider", t, func() { 50 Convey("A testing BuildInfoProvider", t, func() {
101 c := context.Background() 51 c := context.Background()
102 c = memory.Use(c) 52 c = memory.Use(c)
103 53
104 testClient := testLogDogClient{} 54 testClient := testLogDogClient{}
105 testSvc := testSwarmingService{ 55 testSvc := testSwarmingService{
106 host: "swarming.example.com", 56 host: "swarming.example.com",
(...skipping 10 matching lines...) Expand all
117 State: TaskRunning, 67 State: TaskRunning,
118 Tags: []string{ 68 Tags: []string{
119 "allow_milo:1", 69 "allow_milo:1",
120 "foo:1", 70 "foo:1",
121 "bar:2", 71 "bar:2",
122 }, 72 },
123 TryNumber: 1, 73 TryNumber: 1,
124 }, 74 },
125 } 75 }
126 bip := BuildInfoProvider{ 76 bip := BuildInfoProvider{
127 » » » LogdogClientFunc: func(context.Context) (*coordinator.Cl ient, error) { 77 » » » bl: buildLoader{
128 » » » » return &coordinator.Client{ 78 » » » » logDogClientFunc: func(c context.Context, host s tring) (*coordinator.Client, error) {
129 » » » » » C: &testClient, 79 » » » » » if host == "" {
130 » » » » » Host: "example.com", 80 » » » » » » host = "example.com"
131 » » » » }, nil 81 » » » » » }
82 » » » » » return &coordinator.Client{
83 » » » » » » C: &testClient,
84 » » » » » » Host: host,
85 » » » » » }, nil
86 » » » » },
132 }, 87 },
133 swarmingServiceFunc: func(context.Context, string) (swar mingService, error) { 88 swarmingServiceFunc: func(context.Context, string) (swar mingService, error) {
134 return &testSvc, nil 89 return &testSvc, nil
135 }, 90 },
136 } 91 }
137 92
138 logdogStep := miloProto.Step{ 93 logdogStep := miloProto.Step{
139 Command: &miloProto.Step_Command{ 94 Command: &miloProto.Step_Command{
140 CommandLine: []string{"foo", "bar", "baz"}, 95 CommandLine: []string{"foo", "bar", "baz"},
141 }, 96 },
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 } 227 }
273 228
274 for _, tc := range failures { 229 for _, tc := range failures {
275 Convey(fmt.Sprintf("Failes to parse %q / %q (%s)", tc.ta skID, tc.tryNumber, tc.err), func() { 230 Convey(fmt.Sprintf("Failes to parse %q / %q (%s)", tc.ta skID, tc.tryNumber, tc.err), func() {
276 _, err := getRunID(tc.taskID, tc.tryNumber) 231 _, err := getRunID(tc.taskID, tc.tryNumber)
277 So(err, ShouldErrLike, tc.err) 232 So(err, ShouldErrLike, tc.err)
278 }) 233 })
279 } 234 }
280 }) 235 })
281 } 236 }
OLDNEW
« no previous file with comments | « milo/appengine/swarming/buildinfo.go ('k') | milo/appengine/swarming/expectations/build-running-logdog.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698