| 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 "testing" | 9 "testing" |
| 9 | 10 |
| 10 swarming "github.com/luci/luci-go/common/api/swarming/swarming/v1" | 11 swarming "github.com/luci/luci-go/common/api/swarming/swarming/v1" |
| 11 miloProto "github.com/luci/luci-go/common/proto/milo" | 12 miloProto "github.com/luci/luci-go/common/proto/milo" |
| 12 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/logs/v1" | 13 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/logs/v1" |
| 13 "github.com/luci/luci-go/logdog/api/logpb" | 14 "github.com/luci/luci-go/logdog/api/logpb" |
| 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" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 host: "swarming.example.com", | 106 host: "swarming.example.com", |
| 106 req: swarming.SwarmingRpcsTaskRequest{ | 107 req: swarming.SwarmingRpcsTaskRequest{ |
| 107 Properties: &swarming.SwarmingRpcsTaskProperties
{ | 108 Properties: &swarming.SwarmingRpcsTaskProperties
{ |
| 108 Command: []string{"kitchen", "foo", "bar
", "-logdog-project", "testproject", "baz"}, | 109 Command: []string{"kitchen", "foo", "bar
", "-logdog-project", "testproject", "baz"}, |
| 109 }, | 110 }, |
| 110 Tags: []string{ | 111 Tags: []string{ |
| 111 "allow_milo:1", | 112 "allow_milo:1", |
| 112 }, | 113 }, |
| 113 }, | 114 }, |
| 114 res: swarming.SwarmingRpcsTaskResult{ | 115 res: swarming.SwarmingRpcsTaskResult{ |
| 115 » » » » TaskId: "12345", | 116 » » » » TaskId: "12340", |
| 116 State: TaskRunning, | 117 State: TaskRunning, |
| 117 Tags: []string{ | 118 Tags: []string{ |
| 118 "allow_milo:1", | 119 "allow_milo:1", |
| 119 "foo:1", | 120 "foo:1", |
| 120 "bar:2", | 121 "bar:2", |
| 121 }, | 122 }, |
| 123 TryNumber: 1, |
| 122 }, | 124 }, |
| 123 } | 125 } |
| 124 bip := BuildInfoProvider{ | 126 bip := BuildInfoProvider{ |
| 125 LogdogClientFunc: func(context.Context) (*coordinator.Cl
ient, error) { | 127 LogdogClientFunc: func(context.Context) (*coordinator.Cl
ient, error) { |
| 126 return &coordinator.Client{ | 128 return &coordinator.Client{ |
| 127 C: &testClient, | 129 C: &testClient, |
| 128 Host: "example.com", | 130 Host: "example.com", |
| 129 }, nil | 131 }, nil |
| 130 }, | 132 }, |
| 131 swarmingServiceFunc: func(context.Context, string) (swar
mingService, error) { | 133 swarmingServiceFunc: func(context.Context, string) (swar
mingService, error) { |
| 132 return &testSvc, nil | 134 return &testSvc, nil |
| 133 }, | 135 }, |
| 134 } | 136 } |
| 135 | 137 |
| 136 logdogStep := miloProto.Step{ | 138 logdogStep := miloProto.Step{ |
| 137 Command: &miloProto.Step_Command{ | 139 Command: &miloProto.Step_Command{ |
| 138 CommandLine: []string{"foo", "bar", "baz"}, | 140 CommandLine: []string{"foo", "bar", "baz"}, |
| 139 }, | 141 }, |
| 140 Text: []string{"test step"}, | 142 Text: []string{"test step"}, |
| 141 Property: []*miloProto.Step_Property{ | 143 Property: []*miloProto.Step_Property{ |
| 142 {Name: "bar", Value: "log-bar"}, | 144 {Name: "bar", Value: "log-bar"}, |
| 143 }, | 145 }, |
| 144 } | 146 } |
| 145 | 147 |
| 146 biReq := milo.BuildInfoRequest{ | 148 biReq := milo.BuildInfoRequest{ |
| 147 Build: &milo.BuildInfoRequest_Swarming_{ | 149 Build: &milo.BuildInfoRequest_Swarming_{ |
| 148 Swarming: &milo.BuildInfoRequest_Swarming{ | 150 Swarming: &milo.BuildInfoRequest_Swarming{ |
| 149 » » » » » Task: "12345", | 151 » » » » » Task: "12340", |
| 150 }, | 152 }, |
| 151 }, | 153 }, |
| 152 } | 154 } |
| 153 | 155 |
| 154 Convey("Will fail to load a non-Kitchen build.", func() { | 156 Convey("Will fail to load a non-Kitchen build.", func() { |
| 155 testSvc.req.Properties.Command = []string{"not", "kitche
n"} | 157 testSvc.req.Properties.Command = []string{"not", "kitche
n"} |
| 156 | 158 |
| 157 _, err := bip.GetBuildInfo(c, biReq.GetSwarming(), "") | 159 _, err := bip.GetBuildInfo(c, biReq.GetSwarming(), "") |
| 158 So(err, ShouldBeRPCNotFound) | 160 So(err, ShouldBeRPCNotFound) |
| 159 }) | 161 }) |
| 160 | 162 |
| 161 Convey("Can load a build, inferring project from Kitchen CLI.",
func() { | 163 Convey("Can load a build, inferring project from Kitchen CLI.",
func() { |
| 162 » » » testClient.resp = datagramGetResponse("testproject", "sw
arm/swarming.example.com/12345", &logdogStep) | 164 » » » testClient.resp = datagramGetResponse("testproject", "sw
arm/swarming.example.com/12341", &logdogStep) |
| 163 | 165 |
| 164 resp, err := bip.GetBuildInfo(c, biReq.GetSwarming(), ""
) | 166 resp, err := bip.GetBuildInfo(c, biReq.GetSwarming(), ""
) |
| 165 So(err, ShouldBeNil) | 167 So(err, ShouldBeNil) |
| 166 So(testClient.req, ShouldResemble, &logdog.TailRequest{ | 168 So(testClient.req, ShouldResemble, &logdog.TailRequest{ |
| 167 Project: "testproject", | 169 Project: "testproject", |
| 168 » » » » Path: "swarm/swarming.example.com/12345/+/ann
otations", | 170 » » » » Path: "swarm/swarming.example.com/12341/+/ann
otations", |
| 169 State: true, | 171 State: true, |
| 170 }) | 172 }) |
| 171 So(resp, ShouldResemble, &milo.BuildInfoResponse{ | 173 So(resp, ShouldResemble, &milo.BuildInfoResponse{ |
| 172 Project: "testproject", | 174 Project: "testproject", |
| 173 Step: &miloProto.Step{ | 175 Step: &miloProto.Step{ |
| 174 Command: &miloProto.Step_Command{ | 176 Command: &miloProto.Step_Command{ |
| 175 CommandLine: []string{"foo", "ba
r", "baz"}, | 177 CommandLine: []string{"foo", "ba
r", "baz"}, |
| 176 }, | 178 }, |
| 177 Text: []string{"test step"}, | 179 Text: []string{"test step"}, |
| 178 Link: &miloProto.Link{ | 180 Link: &miloProto.Link{ |
| 179 » » » » » » Label: "Task 12345", | 181 » » » » » » Label: "Task 12340", |
| 180 Value: &miloProto.Link_Url{ | 182 Value: &miloProto.Link_Url{ |
| 181 » » » » » » » Url: "https://swarming.e
xample.com/user/task/12345", | 183 » » » » » » » Url: "https://swarming.e
xample.com/user/task/12340", |
| 182 }, | 184 }, |
| 183 }, | 185 }, |
| 184 Property: []*miloProto.Step_Property{ | 186 Property: []*miloProto.Step_Property{ |
| 185 {Name: "bar", Value: "log-bar"}, | 187 {Name: "bar", Value: "log-bar"}, |
| 186 }, | 188 }, |
| 187 }, | 189 }, |
| 188 AnnotationStream: &miloProto.LogdogStream{ | 190 AnnotationStream: &miloProto.LogdogStream{ |
| 189 Server: "example.com", | 191 Server: "example.com", |
| 190 » » » » » Prefix: "swarm/swarming.example.com/1234
5", | 192 » » » » » Prefix: "swarm/swarming.example.com/1234
1", |
| 191 Name: "annotations", | 193 Name: "annotations", |
| 192 }, | 194 }, |
| 193 }) | 195 }) |
| 194 }) | 196 }) |
| 195 | 197 |
| 196 Convey("Will fail to load Kitchen without LogDog and no project
hint.", func() { | 198 Convey("Will fail to load Kitchen without LogDog and no project
hint.", func() { |
| 197 testSvc.req.Properties.Command = []string{"kitchen"} | 199 testSvc.req.Properties.Command = []string{"kitchen"} |
| 198 | 200 |
| 199 _, err := bip.GetBuildInfo(c, biReq.GetSwarming(), "") | 201 _, err := bip.GetBuildInfo(c, biReq.GetSwarming(), "") |
| 200 So(err, ShouldBeRPCNotFound) | 202 So(err, ShouldBeRPCNotFound) |
| 201 }) | 203 }) |
| 202 | 204 |
| 203 Convey("Will load Kitchen without LogDog if there is a project h
int.", func() { | 205 Convey("Will load Kitchen without LogDog if there is a project h
int.", func() { |
| 204 biReq.ProjectHint = "testproject" | 206 biReq.ProjectHint = "testproject" |
| 205 testSvc.req.Properties.Command = []string{"kitchen"} | 207 testSvc.req.Properties.Command = []string{"kitchen"} |
| 206 » » » testClient.resp = datagramGetResponse("testproject", "sw
arm/swarming.example.com/12345", &logdogStep) | 208 » » » testClient.resp = datagramGetResponse("testproject", "sw
arm/swarming.example.com/12341", &logdogStep) |
| 207 | 209 |
| 208 resp, err := bip.GetBuildInfo(c, biReq.GetSwarming(), "t
estproject") | 210 resp, err := bip.GetBuildInfo(c, biReq.GetSwarming(), "t
estproject") |
| 209 So(err, ShouldBeNil) | 211 So(err, ShouldBeNil) |
| 210 So(testClient.req, ShouldResemble, &logdog.TailRequest{ | 212 So(testClient.req, ShouldResemble, &logdog.TailRequest{ |
| 211 Project: "testproject", | 213 Project: "testproject", |
| 212 » » » » Path: "swarm/swarming.example.com/12345/+/ann
otations", | 214 » » » » Path: "swarm/swarming.example.com/12341/+/ann
otations", |
| 213 State: true, | 215 State: true, |
| 214 }) | 216 }) |
| 215 So(resp, ShouldResemble, &milo.BuildInfoResponse{ | 217 So(resp, ShouldResemble, &milo.BuildInfoResponse{ |
| 216 Project: "testproject", | 218 Project: "testproject", |
| 217 Step: &miloProto.Step{ | 219 Step: &miloProto.Step{ |
| 218 Command: &miloProto.Step_Command{ | 220 Command: &miloProto.Step_Command{ |
| 219 CommandLine: []string{"foo", "ba
r", "baz"}, | 221 CommandLine: []string{"foo", "ba
r", "baz"}, |
| 220 }, | 222 }, |
| 221 Text: []string{"test step"}, | 223 Text: []string{"test step"}, |
| 222 Link: &miloProto.Link{ | 224 Link: &miloProto.Link{ |
| 223 » » » » » » Label: "Task 12345", | 225 » » » » » » Label: "Task 12340", |
| 224 Value: &miloProto.Link_Url{ | 226 Value: &miloProto.Link_Url{ |
| 225 » » » » » » » Url: "https://swarming.e
xample.com/user/task/12345", | 227 » » » » » » » Url: "https://swarming.e
xample.com/user/task/12340", |
| 226 }, | 228 }, |
| 227 }, | 229 }, |
| 228 Property: []*miloProto.Step_Property{ | 230 Property: []*miloProto.Step_Property{ |
| 229 {Name: "bar", Value: "log-bar"}, | 231 {Name: "bar", Value: "log-bar"}, |
| 230 }, | 232 }, |
| 231 }, | 233 }, |
| 232 AnnotationStream: &miloProto.LogdogStream{ | 234 AnnotationStream: &miloProto.LogdogStream{ |
| 233 Server: "example.com", | 235 Server: "example.com", |
| 234 » » » » » Prefix: "swarm/swarming.example.com/1234
5", | 236 » » » » » Prefix: "swarm/swarming.example.com/1234
1", |
| 235 Name: "annotations", | 237 Name: "annotations", |
| 236 }, | 238 }, |
| 237 }) | 239 }) |
| 238 }) | 240 }) |
| 239 }) | 241 }) |
| 240 } | 242 } |
| 243 |
| 244 func TestGetRunID(t *testing.T) { |
| 245 t.Parallel() |
| 246 |
| 247 successes := []struct { |
| 248 taskID string |
| 249 tryNumber int64 |
| 250 runID string |
| 251 }{ |
| 252 {"3442825749e6e110", 1, "3442825749e6e111"}, |
| 253 } |
| 254 |
| 255 failures := []struct { |
| 256 taskID string |
| 257 tryNumber int64 |
| 258 err string |
| 259 }{ |
| 260 {"", 1, "swarming task ID is empty"}, |
| 261 {"3442825749e6e110", 16, "exceeds 4 bits"}, |
| 262 {"3442825749e6e11M", 1, "failed to parse hex from rune"}, |
| 263 } |
| 264 |
| 265 Convey("Testing BuildInfo's getRunID", t, func() { |
| 266 for _, tc := range successes { |
| 267 Convey(fmt.Sprintf("Successfully processes %q / %q => %q
", tc.taskID, tc.tryNumber, tc.runID), func() { |
| 268 v, err := getRunID(tc.taskID, tc.tryNumber) |
| 269 So(err, ShouldBeNil) |
| 270 So(v, ShouldEqual, tc.runID) |
| 271 }) |
| 272 } |
| 273 |
| 274 for _, tc := range failures { |
| 275 Convey(fmt.Sprintf("Failes to parse %q / %q (%s)", tc.ta
skID, tc.tryNumber, tc.err), func() { |
| 276 _, err := getRunID(tc.taskID, tc.tryNumber) |
| 277 So(err, ShouldErrLike, tc.err) |
| 278 }) |
| 279 } |
| 280 }) |
| 281 } |
| OLD | NEW |