| 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 "github.com/luci/luci-go/common/errors" | 23 "github.com/luci/luci-go/common/errors" |
| 24 miloProto "github.com/luci/luci-go/common/proto/milo" | 24 miloProto "github.com/luci/luci-go/common/proto/milo" |
| 25 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/logs/v1" | 25 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/logs/v1" |
| 26 "github.com/luci/luci-go/logdog/api/logpb" | 26 "github.com/luci/luci-go/logdog/api/logpb" |
| 27 "github.com/luci/luci-go/logdog/client/coordinator" | 27 "github.com/luci/luci-go/logdog/client/coordinator" |
| 28 "github.com/luci/luci-go/milo/api/resp" | 28 "github.com/luci/luci-go/milo/api/resp" |
| 29 » "github.com/luci/luci-go/milo/appengine/settings" | 29 » "github.com/luci/luci-go/milo/appengine/common" |
| 30 "github.com/luci/luci-go/server/templates" | 30 "github.com/luci/luci-go/server/templates" |
| 31 ) | 31 ) |
| 32 | 32 |
| 33 type testCase struct { | 33 type testCase struct { |
| 34 name string | 34 name string |
| 35 | 35 |
| 36 swarmResult string | 36 swarmResult string |
| 37 swarmOutput string | 37 swarmOutput string |
| 38 annotations string | 38 annotations string |
| 39 } | 39 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 func (svc debugSwarmingService) getSwarmingRequest(c context.Context, taskID str
ing) ( | 140 func (svc debugSwarmingService) getSwarmingRequest(c context.Context, taskID str
ing) ( |
| 141 *swarming.SwarmingRpcsTaskRequest, error) { | 141 *swarming.SwarmingRpcsTaskRequest, error) { |
| 142 | 142 |
| 143 return nil, errors.New("not implemented") | 143 return nil, errors.New("not implemented") |
| 144 } | 144 } |
| 145 | 145 |
| 146 func (svc debugSwarmingService) getTaskOutput(c context.Context, taskID string)
(string, error) { | 146 func (svc debugSwarmingService) getTaskOutput(c context.Context, taskID string)
(string, error) { |
| 147 return svc.tc.getSwarmingOutput(), nil | 147 return svc.tc.getSwarmingOutput(), nil |
| 148 } | 148 } |
| 149 | 149 |
| 150 // TestableLog is a subclass of Log that interfaces with TestableHandler and | 150 // LogTestData returns sample test data for log pages. |
| 151 // includes sample test data. | 151 func LogTestData() []common.TestBundle { |
| 152 type TestableLog struct{ Log } | 152 » return []common.TestBundle{ |
| 153 | |
| 154 // TestableBuild is a subclass of Build that interfaces with TestableHandler and | |
| 155 // includes sample test data. | |
| 156 type TestableBuild struct{ Build } | |
| 157 | |
| 158 // TestData returns sample test data. | |
| 159 func (l TestableLog) TestData() []settings.TestBundle { | |
| 160 » return []settings.TestBundle{ | |
| 161 { | 153 { |
| 162 Description: "Basic log", | 154 Description: "Basic log", |
| 163 Data: templates.Args{ | 155 Data: templates.Args{ |
| 164 "Log": "This is the log", | 156 "Log": "This is the log", |
| 165 "Closed": true, | 157 "Closed": true, |
| 166 }, | 158 }, |
| 167 }, | 159 }, |
| 168 } | 160 } |
| 169 } | 161 } |
| 170 | 162 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 Content: &logpb.LogEntry_Datagram{ | 220 Content: &logpb.LogEntry_Datagram{ |
| 229 Datagram: &logpb.Datagram{ | 221 Datagram: &logpb.Datagram{ |
| 230 Data: data, | 222 Data: data, |
| 231 }, | 223 }, |
| 232 }, | 224 }, |
| 233 }, | 225 }, |
| 234 }, | 226 }, |
| 235 } | 227 } |
| 236 } | 228 } |
| 237 | 229 |
| 238 // TestData returns sample test data. | 230 // BuildTestData returns sample test data for swarming build pages. |
| 239 func (b TestableBuild) TestData() []settings.TestBundle { | 231 func BuildTestData() []common.TestBundle { |
| 240 basic := resp.MiloBuild{ | 232 basic := resp.MiloBuild{ |
| 241 Summary: resp.BuildComponent{ | 233 Summary: resp.BuildComponent{ |
| 242 Label: "Test swarming build", | 234 Label: "Test swarming build", |
| 243 Status: resp.Success, | 235 Status: resp.Success, |
| 244 Started: time.Date(2016, 1, 2, 15, 4, 5, 999999999, tim
e.UTC), | 236 Started: time.Date(2016, 1, 2, 15, 4, 5, 999999999, tim
e.UTC), |
| 245 Finished: time.Date(2016, 1, 2, 15, 4, 6, 999999999, tim
e.UTC), | 237 Finished: time.Date(2016, 1, 2, 15, 4, 6, 999999999, tim
e.UTC), |
| 246 Duration: time.Second, | 238 Duration: time.Second, |
| 247 }, | 239 }, |
| 248 } | 240 } |
| 249 » results := []settings.TestBundle{ | 241 » results := []common.TestBundle{ |
| 250 { | 242 { |
| 251 Description: "Basic successful build", | 243 Description: "Basic successful build", |
| 252 Data: templates.Args{"Build": basic}, | 244 Data: templates.Args{"Build": basic}, |
| 253 }, | 245 }, |
| 254 } | 246 } |
| 255 c := context.Background() | 247 c := context.Background() |
| 256 c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11, 0, 0, 0,
time.UTC)) | 248 c, _ = testclock.UseTime(c, time.Date(2016, time.March, 14, 11, 0, 0, 0,
time.UTC)) |
| 257 c = memory.Use(c) | 249 c = memory.Use(c) |
| 258 | 250 |
| 259 for _, tc := range getTestCases() { | 251 for _, tc := range getTestCases() { |
| 260 svc := debugSwarmingService{tc} | 252 svc := debugSwarmingService{tc} |
| 261 bl := buildLoader{ | 253 bl := buildLoader{ |
| 262 logDogClientFunc: logDogClientFunc(tc), | 254 logDogClientFunc: logDogClientFunc(tc), |
| 263 } | 255 } |
| 264 | 256 |
| 265 build, err := bl.swarmingBuildImpl(c, svc, "foo", tc.name) | 257 build, err := bl.swarmingBuildImpl(c, svc, "foo", tc.name) |
| 266 if err != nil { | 258 if err != nil { |
| 267 panic(fmt.Errorf("Error while processing %s: %s", tc.nam
e, err)) | 259 panic(fmt.Errorf("Error while processing %s: %s", tc.nam
e, err)) |
| 268 } | 260 } |
| 269 » » results = append(results, settings.TestBundle{ | 261 » » results = append(results, common.TestBundle{ |
| 270 Description: tc.name, | 262 Description: tc.name, |
| 271 Data: templates.Args{"Build": build}, | 263 Data: templates.Args{"Build": build}, |
| 272 }) | 264 }) |
| 273 } | 265 } |
| 274 return results | 266 return results |
| 275 } | 267 } |
| OLD | NEW |