Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/grpc/grpcutil" | |
| 13 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/logs/v1" | 14 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/logs/v1" |
| 14 "github.com/luci/luci-go/logdog/client/coordinator" | 15 "github.com/luci/luci-go/logdog/client/coordinator" |
| 15 milo "github.com/luci/luci-go/milo/api/proto" | 16 milo "github.com/luci/luci-go/milo/api/proto" |
| 16 | 17 |
| 17 "github.com/luci/gae/impl/memory" | 18 "github.com/luci/gae/impl/memory" |
| 18 | 19 |
| 19 "golang.org/x/net/context" | 20 "golang.org/x/net/context" |
| 20 | 21 |
| 21 . "github.com/luci/luci-go/common/testing/assertions" | 22 . "github.com/luci/luci-go/common/testing/assertions" |
| 22 . "github.com/smartystreets/goconvey/convey" | 23 . "github.com/smartystreets/goconvey/convey" |
| 23 ) | 24 ) |
| 24 | 25 |
| 25 type testSwarmingService struct { | 26 type testSwarmingService struct { |
| 26 swarmingService | 27 swarmingService |
| 27 | 28 |
| 28 host string | 29 host string |
| 29 req swarming.SwarmingRpcsTaskRequest | 30 req swarming.SwarmingRpcsTaskRequest |
| 30 res swarming.SwarmingRpcsTaskResult | 31 res swarming.SwarmingRpcsTaskResult |
| 32 out string | |
| 31 } | 33 } |
| 32 | 34 |
| 33 func (sf *testSwarmingService) getHost() string { return sf.host } | 35 func (sf *testSwarmingService) getHost() string { return sf.host } |
| 34 | 36 |
| 35 func (sf *testSwarmingService) getSwarmingResult(c context.Context, taskID strin g) ( | 37 func (sf *testSwarmingService) getSwarmingResult(c context.Context, taskID strin g) ( |
| 36 *swarming.SwarmingRpcsTaskResult, error) { | 38 *swarming.SwarmingRpcsTaskResult, error) { |
| 37 | 39 |
| 38 return &sf.res, nil | 40 return &sf.res, nil |
| 39 } | 41 } |
| 40 | 42 |
| 41 func (sf *testSwarmingService) getSwarmingRequest(c context.Context, taskID stri ng) ( | 43 func (sf *testSwarmingService) getSwarmingRequest(c context.Context, taskID stri ng) ( |
| 42 *swarming.SwarmingRpcsTaskRequest, error) { | 44 *swarming.SwarmingRpcsTaskRequest, error) { |
| 43 | 45 |
| 44 return &sf.req, nil | 46 return &sf.req, nil |
| 45 } | 47 } |
| 46 | 48 |
| 49 func (sf *testSwarmingService) getTaskOutput(c context.Context, taskID string) ( string, error) { | |
| 50 return sf.out, nil | |
| 51 } | |
| 52 | |
| 47 func TestBuildInfo(t *testing.T) { | 53 func TestBuildInfo(t *testing.T) { |
| 48 t.Parallel() | 54 t.Parallel() |
| 49 | 55 |
| 50 Convey("A testing BuildInfoProvider", t, func() { | 56 Convey("A testing BuildInfoProvider", t, func() { |
| 51 c := context.Background() | 57 c := context.Background() |
| 52 c = memory.Use(c) | 58 c = memory.Use(c) |
| 53 | 59 |
| 54 testClient := testLogDogClient{} | 60 testClient := testLogDogClient{} |
| 55 testSvc := testSwarmingService{ | 61 testSvc := testSwarmingService{ |
| 56 host: "swarming.example.com", | 62 host: "swarming.example.com", |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 Property: []*miloProto.Step_Property{ | 191 Property: []*miloProto.Step_Property{ |
| 186 {Name: "bar", Value: "log-bar"}, | 192 {Name: "bar", Value: "log-bar"}, |
| 187 }, | 193 }, |
| 188 }, | 194 }, |
| 189 AnnotationStream: &miloProto.LogdogStream{ | 195 AnnotationStream: &miloProto.LogdogStream{ |
| 190 Server: "example.com", | 196 Server: "example.com", |
| 191 Prefix: "swarm/swarming.example.com/1234 1", | 197 Prefix: "swarm/swarming.example.com/1234 1", |
| 192 Name: "annotations", | 198 Name: "annotations", |
| 193 }, | 199 }, |
| 194 }) | 200 }) |
| 201 | |
| 202 Convey("Will return NotFound if the build is internal", func() { | |
| 203 testSvc.res.Tags = testSvc.res.Tags[1:] | |
| 204 testSvc.req.Tags = testSvc.req.Tags[1:] | |
|
nodir
2017/06/08 14:39:12
undup line or testSvc.req.Tags = testSvc.req.Tags[
| |
| 205 _, err := bip.GetBuildInfo(c, biReq.GetSwarming( ), "testproject") | |
| 206 So(err, ShouldResemble, grpcutil.NotFound) | |
| 207 }) | |
| 195 }) | 208 }) |
| 196 }) | 209 }) |
| 197 } | 210 } |
| 198 | 211 |
| 199 func TestGetRunID(t *testing.T) { | 212 func TestGetRunID(t *testing.T) { |
| 200 t.Parallel() | 213 t.Parallel() |
| 201 | 214 |
| 202 successes := []struct { | 215 successes := []struct { |
| 203 taskID string | 216 taskID string |
| 204 tryNumber int64 | 217 tryNumber int64 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 227 } | 240 } |
| 228 | 241 |
| 229 for _, tc := range failures { | 242 for _, tc := range failures { |
| 230 Convey(fmt.Sprintf("Failes to parse %q / %q (%s)", tc.ta skID, tc.tryNumber, tc.err), func() { | 243 Convey(fmt.Sprintf("Failes to parse %q / %q (%s)", tc.ta skID, tc.tryNumber, tc.err), func() { |
| 231 _, err := getRunID(tc.taskID, tc.tryNumber) | 244 _, err := getRunID(tc.taskID, tc.tryNumber) |
| 232 So(err, ShouldErrLike, tc.err) | 245 So(err, ShouldErrLike, tc.err) |
| 233 }) | 246 }) |
| 234 } | 247 } |
| 235 }) | 248 }) |
| 236 } | 249 } |
| OLD | NEW |