| 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" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 "github.com/luci/luci-go/milo/appengine/common" | 31 "github.com/luci/luci-go/milo/appengine/common" |
| 32 "github.com/luci/luci-go/milo/appengine/common/model" | 32 "github.com/luci/luci-go/milo/appengine/common/model" |
| 33 "github.com/luci/luci-go/server/auth" | 33 "github.com/luci/luci-go/server/auth" |
| 34 "github.com/luci/luci-go/server/auth/authtest" | 34 "github.com/luci/luci-go/server/auth/authtest" |
| 35 "github.com/luci/luci-go/server/templates" | 35 "github.com/luci/luci-go/server/templates" |
| 36 ) | 36 ) |
| 37 | 37 |
| 38 type testCase struct { | 38 type testCase struct { |
| 39 name string | 39 name string |
| 40 | 40 |
| 41 swarmingRelDir string |
| 42 |
| 41 swarmResult string | 43 swarmResult string |
| 42 swarmOutput string | 44 swarmOutput string |
| 43 annotations string | 45 annotations string |
| 44 } | 46 } |
| 45 | 47 |
| 46 func getTestCases() []*testCase { | 48 func getTestCases(swarmingRelDir string) []*testCase { |
| 47 testCases := make(map[string]*testCase) | 49 testCases := make(map[string]*testCase) |
| 48 | 50 |
| 49 » // References "milo/appengine/swarming/testdata". | 51 » // References "milo/appengine/job_source/swarming/testdata". |
| 50 » testdata := filepath.Join("..", "swarming", "testdata") | 52 » testdata := filepath.Join(swarmingRelDir, "testdata") |
| 51 f, err := ioutil.ReadDir(testdata) | 53 f, err := ioutil.ReadDir(testdata) |
| 52 if err != nil { | 54 if err != nil { |
| 53 panic(err) | 55 panic(err) |
| 54 } | 56 } |
| 55 for _, fi := range f { | 57 for _, fi := range f { |
| 56 fileName := fi.Name() | 58 fileName := fi.Name() |
| 57 parts := strings.SplitN(fileName, ".", 2) | 59 parts := strings.SplitN(fileName, ".", 2) |
| 58 | 60 |
| 59 name := parts[0] | 61 name := parts[0] |
| 60 tc := testCases[name] | 62 tc := testCases[name] |
| 61 if tc == nil { | 63 if tc == nil { |
| 62 tc = &testCase{name: name} | 64 tc = &testCase{name: name} |
| 63 testCases[name] = tc | 65 testCases[name] = tc |
| 64 } | 66 } |
| 67 tc.swarmingRelDir = swarmingRelDir |
| 65 | 68 |
| 66 switch { | 69 switch { |
| 67 case len(parts) == 1: | 70 case len(parts) == 1: |
| 68 tc.swarmOutput = fileName | 71 tc.swarmOutput = fileName |
| 69 case parts[1] == "swarm": | 72 case parts[1] == "swarm": |
| 70 tc.swarmResult = fileName | 73 tc.swarmResult = fileName |
| 71 case parts[1] == "pb.txt": | 74 case parts[1] == "pb.txt": |
| 72 tc.annotations = fileName | 75 tc.annotations = fileName |
| 73 } | 76 } |
| 74 } | 77 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 89 } | 92 } |
| 90 | 93 |
| 91 func (tc *testCase) getContent(name string) []byte { | 94 func (tc *testCase) getContent(name string) []byte { |
| 92 if name == "" { | 95 if name == "" { |
| 93 return nil | 96 return nil |
| 94 } | 97 } |
| 95 | 98 |
| 96 // ../swarming below assumes that | 99 // ../swarming below assumes that |
| 97 // - this code is not executed by tests outside of this dir | 100 // - this code is not executed by tests outside of this dir |
| 98 // - this dir is a sibling of frontend dir | 101 // - this dir is a sibling of frontend dir |
| 99 » path := filepath.Join("..", "swarming", "testdata", name) | 102 » path := filepath.Join(tc.swarmingRelDir, "testdata", name) |
| 100 data, err := ioutil.ReadFile(path) | 103 data, err := ioutil.ReadFile(path) |
| 101 if err != nil { | 104 if err != nil { |
| 102 panic(fmt.Errorf("failed to read [%s]: %s", path, err)) | 105 panic(fmt.Errorf("failed to read [%s]: %s", path, err)) |
| 103 } | 106 } |
| 104 return data | 107 return data |
| 105 } | 108 } |
| 106 | 109 |
| 107 func (tc *testCase) getSwarmingResult() *swarming.SwarmingRpcsTaskResult { | 110 func (tc *testCase) getSwarmingResult() *swarming.SwarmingRpcsTaskResult { |
| 108 var sr swarming.SwarmingRpcsTaskResult | 111 var sr swarming.SwarmingRpcsTaskResult |
| 109 data := tc.getContent(tc.swarmResult) | 112 data := tc.getContent(tc.swarmResult) |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 Datagram: &logpb.Datagram{ | 229 Datagram: &logpb.Datagram{ |
| 227 Data: data, | 230 Data: data, |
| 228 }, | 231 }, |
| 229 }, | 232 }, |
| 230 }, | 233 }, |
| 231 }, | 234 }, |
| 232 } | 235 } |
| 233 } | 236 } |
| 234 | 237 |
| 235 // BuildTestData returns sample test data for swarming build pages. | 238 // BuildTestData returns sample test data for swarming build pages. |
| 236 func BuildTestData() []common.TestBundle { | 239 func BuildTestData(swarmingRelDir string) []common.TestBundle { |
| 237 basic := resp.MiloBuild{ | 240 basic := resp.MiloBuild{ |
| 238 Summary: resp.BuildComponent{ | 241 Summary: resp.BuildComponent{ |
| 239 Label: "Test swarming build", | 242 Label: "Test swarming build", |
| 240 Status: model.Success, | 243 Status: model.Success, |
| 241 Started: time.Date(2016, 1, 2, 15, 4, 5, 999999999, tim
e.UTC), | 244 Started: time.Date(2016, 1, 2, 15, 4, 5, 999999999, tim
e.UTC), |
| 242 Finished: time.Date(2016, 1, 2, 15, 4, 6, 999999999, tim
e.UTC), | 245 Finished: time.Date(2016, 1, 2, 15, 4, 6, 999999999, tim
e.UTC), |
| 243 Duration: time.Second, | 246 Duration: time.Second, |
| 244 }, | 247 }, |
| 245 } | 248 } |
| 246 results := []common.TestBundle{ | 249 results := []common.TestBundle{ |
| 247 { | 250 { |
| 248 Description: "Basic successful build", | 251 Description: "Basic successful build", |
| 249 Data: templates.Args{"Build": basic}, | 252 Data: templates.Args{"Build": basic}, |
| 250 }, | 253 }, |
| 251 } | 254 } |
| 252 c := context.Background() | 255 c := context.Background() |
| 253 c = memory.UseWithAppID(c, "dev~luci-milo") | 256 c = memory.UseWithAppID(c, "dev~luci-milo") |
| 254 c = testconfig.WithCommonClient(c, memcfg.New(aclConfgs)) | 257 c = testconfig.WithCommonClient(c, memcfg.New(aclConfgs)) |
| 255 c = auth.WithState(c, &authtest.FakeState{ | 258 c = auth.WithState(c, &authtest.FakeState{ |
| 256 Identity: "user:alicebob@google.com", | 259 Identity: "user:alicebob@google.com", |
| 257 IdentityGroups: []string{"all", "googlers"}, | 260 IdentityGroups: []string{"all", "googlers"}, |
| 258 }) | 261 }) |
| 259 c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11, 0, 0, 0,
time.UTC)) | 262 c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11, 0, 0, 0,
time.UTC)) |
| 260 | 263 |
| 261 » for _, tc := range getTestCases() { | 264 » for _, tc := range getTestCases(swarmingRelDir) { |
| 262 svc := debugSwarmingService{tc} | 265 svc := debugSwarmingService{tc} |
| 263 bl := buildLoader{ | 266 bl := buildLoader{ |
| 264 logDogClientFunc: logDogClientFunc(tc), | 267 logDogClientFunc: logDogClientFunc(tc), |
| 265 } | 268 } |
| 266 | 269 |
| 267 build, err := bl.swarmingBuildImpl(c, svc, "foo", tc.name) | 270 build, err := bl.swarmingBuildImpl(c, svc, "foo", tc.name) |
| 268 if err != nil { | 271 if err != nil { |
| 269 panic(fmt.Errorf("Error while processing %s: %s", tc.nam
e, err)) | 272 panic(fmt.Errorf("Error while processing %s: %s", tc.nam
e, err)) |
| 270 } | 273 } |
| 271 results = append(results, common.TestBundle{ | 274 results = append(results, common.TestBundle{ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 287 ` | 290 ` |
| 288 | 291 |
| 289 var aclConfgs = map[string]memcfg.ConfigSet{ | 292 var aclConfgs = map[string]memcfg.ConfigSet{ |
| 290 "projects/secret": { | 293 "projects/secret": { |
| 291 "project.cfg": secretProjectCfg, | 294 "project.cfg": secretProjectCfg, |
| 292 }, | 295 }, |
| 293 "projects/opensource": { | 296 "projects/opensource": { |
| 294 "project.cfg": publicProjectCfg, | 297 "project.cfg": publicProjectCfg, |
| 295 }, | 298 }, |
| 296 } | 299 } |
| OLD | NEW |