| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 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 "encoding/json" | 8 "encoding/json" |
| 9 "fmt" | 9 "fmt" |
| 10 "io/ioutil" | 10 "io/ioutil" |
| 11 "path/filepath" | 11 "path/filepath" |
| 12 "sort" | 12 "sort" |
| 13 "strings" | 13 "strings" |
| 14 "time" | 14 "time" |
| 15 | 15 |
| 16 "github.com/golang/protobuf/proto" | 16 "github.com/golang/protobuf/proto" |
| 17 "github.com/luci/gae/impl/memory" | 17 "github.com/luci/gae/impl/memory" |
| 18 "golang.org/x/net/context" | 18 "golang.org/x/net/context" |
| 19 "google.golang.org/grpc" | 19 "google.golang.org/grpc" |
| 20 | 20 |
| 21 swarming "github.com/luci/luci-go/common/api/swarming/swarming/v1" | 21 swarming "github.com/luci/luci-go/common/api/swarming/swarming/v1" |
| 22 "github.com/luci/luci-go/common/clock/testclock" | 22 "github.com/luci/luci-go/common/clock/testclock" |
| 23 memcfg "github.com/luci/luci-go/common/config/impl/memory" |
| 23 "github.com/luci/luci-go/common/errors" | 24 "github.com/luci/luci-go/common/errors" |
| 24 miloProto "github.com/luci/luci-go/common/proto/milo" | 25 miloProto "github.com/luci/luci-go/common/proto/milo" |
| 25 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/logs/v1" | 26 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/logs/v1" |
| 26 "github.com/luci/luci-go/logdog/api/logpb" | 27 "github.com/luci/luci-go/logdog/api/logpb" |
| 27 "github.com/luci/luci-go/logdog/client/coordinator" | 28 "github.com/luci/luci-go/logdog/client/coordinator" |
| 29 "github.com/luci/luci-go/luci_config/server/cfgclient/backend/testconfig
" |
| 28 "github.com/luci/luci-go/milo/api/resp" | 30 "github.com/luci/luci-go/milo/api/resp" |
| 29 "github.com/luci/luci-go/milo/appengine/common" | 31 "github.com/luci/luci-go/milo/appengine/common" |
| 32 "github.com/luci/luci-go/server/auth" |
| 33 "github.com/luci/luci-go/server/auth/authtest" |
| 30 "github.com/luci/luci-go/server/templates" | 34 "github.com/luci/luci-go/server/templates" |
| 31 ) | 35 ) |
| 32 | 36 |
| 33 type testCase struct { | 37 type testCase struct { |
| 34 name string | 38 name string |
| 35 | 39 |
| 36 swarmResult string | 40 swarmResult string |
| 37 swarmOutput string | 41 swarmOutput string |
| 38 annotations string | 42 annotations string |
| 39 } | 43 } |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 Duration: time.Second, | 242 Duration: time.Second, |
| 239 }, | 243 }, |
| 240 } | 244 } |
| 241 results := []common.TestBundle{ | 245 results := []common.TestBundle{ |
| 242 { | 246 { |
| 243 Description: "Basic successful build", | 247 Description: "Basic successful build", |
| 244 Data: templates.Args{"Build": basic}, | 248 Data: templates.Args{"Build": basic}, |
| 245 }, | 249 }, |
| 246 } | 250 } |
| 247 c := context.Background() | 251 c := context.Background() |
| 252 c = memory.UseWithAppID(c, "dev~luci-milo") |
| 253 c = testconfig.WithCommonClient(c, memcfg.New(aclConfgs)) |
| 254 c = auth.WithState(c, &authtest.FakeState{ |
| 255 Identity: "user:alicebob@google.com", |
| 256 IdentityGroups: []string{"all", "googlers"}, |
| 257 }) |
| 248 c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11, 0, 0, 0,
time.UTC)) | 258 c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11, 0, 0, 0,
time.UTC)) |
| 249 c = memory.Use(c) | |
| 250 | 259 |
| 251 for _, tc := range getTestCases() { | 260 for _, tc := range getTestCases() { |
| 252 svc := debugSwarmingService{tc} | 261 svc := debugSwarmingService{tc} |
| 253 bl := buildLoader{ | 262 bl := buildLoader{ |
| 254 logDogClientFunc: logDogClientFunc(tc), | 263 logDogClientFunc: logDogClientFunc(tc), |
| 255 } | 264 } |
| 256 | 265 |
| 257 build, err := bl.swarmingBuildImpl(c, svc, "foo", tc.name) | 266 build, err := bl.swarmingBuildImpl(c, svc, "foo", tc.name) |
| 258 if err != nil { | 267 if err != nil { |
| 259 panic(fmt.Errorf("Error while processing %s: %s", tc.nam
e, err)) | 268 panic(fmt.Errorf("Error while processing %s: %s", tc.nam
e, err)) |
| 260 } | 269 } |
| 261 results = append(results, common.TestBundle{ | 270 results = append(results, common.TestBundle{ |
| 262 Description: tc.name, | 271 Description: tc.name, |
| 263 Data: templates.Args{"Build": build}, | 272 Data: templates.Args{"Build": build}, |
| 264 }) | 273 }) |
| 265 } | 274 } |
| 266 return results | 275 return results |
| 267 } | 276 } |
| 277 |
| 278 var secretProjectCfg = ` |
| 279 name: "secret" |
| 280 access: "group:googlers" |
| 281 ` |
| 282 |
| 283 var publicProjectCfg = ` |
| 284 name: "opensource" |
| 285 access: "group:all" |
| 286 ` |
| 287 |
| 288 var aclConfgs = map[string]memcfg.ConfigSet{ |
| 289 "projects/secret": { |
| 290 "project.cfg": secretProjectCfg, |
| 291 }, |
| 292 "projects/opensource": { |
| 293 "project.cfg": publicProjectCfg, |
| 294 }, |
| 295 } |
| OLD | NEW |