| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package cipd | 5 package cipd |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "fmt" | 9 "fmt" |
| 10 "io" | 10 "io" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 Reply: `{"status":"VERIFYING"}`, | 63 Reply: `{"status":"VERIFYING"}`, |
| 64 }) | 64 }) |
| 65 } | 65 } |
| 66 client := mockClient(c, calls) | 66 client := mockClient(c, calls) |
| 67 client.storage = &mockedStorage{c, nil} | 67 client.storage = &mockedStorage{c, nil} |
| 68 err := client.UploadToCAS("abc", nil, nil) | 68 err := client.UploadToCAS("abc", nil, nil) |
| 69 So(err, ShouldEqual, ErrFinalizationTimeout) | 69 So(err, ShouldEqual, ErrFinalizationTimeout) |
| 70 }) | 70 }) |
| 71 } | 71 } |
| 72 | 72 |
| 73 func TestResolveVersion(t *testing.T) { |
| 74 Convey("ResolveVersion works", t, func(c C) { |
| 75 client := mockClient(c, []expectedHTTPCall{ |
| 76 { |
| 77 Method: "GET", |
| 78 Path: "/_ah/api/repo/v1/instance/resolve", |
| 79 Query: url.Values{ |
| 80 "package_name": []string{"pkgname"}, |
| 81 "version": []string{"tag_key:value"
}, |
| 82 }, |
| 83 Reply: `{ |
| 84 "status": "SUCCESS", |
| 85 "instance_id": "aaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaa" |
| 86 }`, |
| 87 }, |
| 88 }) |
| 89 pin, err := client.ResolveVersion("pkgname", "tag_key:value") |
| 90 So(err, ShouldBeNil) |
| 91 So(pin, ShouldResemble, common.Pin{ |
| 92 PackageName: "pkgname", |
| 93 InstanceID: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", |
| 94 }) |
| 95 }) |
| 96 |
| 97 Convey("ResolveVersion with instance ID", t, func(c C) { |
| 98 // No calls to the backend expected. |
| 99 client := mockClient(c, nil) |
| 100 pin, err := client.ResolveVersion("pkgname", "aaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaa") |
| 101 So(err, ShouldBeNil) |
| 102 So(pin, ShouldResemble, common.Pin{ |
| 103 PackageName: "pkgname", |
| 104 InstanceID: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", |
| 105 }) |
| 106 }) |
| 107 |
| 108 Convey("ResolveVersion bad package name", t, func(c C) { |
| 109 client := mockClient(c, nil) |
| 110 _, err := client.ResolveVersion("bad package", "tag_key:value") |
| 111 So(err, ShouldNotBeNil) |
| 112 }) |
| 113 |
| 114 Convey("ResolveVersion bad version", t, func(c C) { |
| 115 client := mockClient(c, nil) |
| 116 _, err := client.ResolveVersion("pkgname", "BAD_TAG:") |
| 117 So(err, ShouldNotBeNil) |
| 118 }) |
| 119 } |
| 120 |
| 73 func TestRegisterInstance(t *testing.T) { | 121 func TestRegisterInstance(t *testing.T) { |
| 74 Convey("Mocking a package instance", t, func() { | 122 Convey("Mocking a package instance", t, func() { |
| 75 // Build an empty package to be uploaded. | 123 // Build an empty package to be uploaded. |
| 76 out := bytes.Buffer{} | 124 out := bytes.Buffer{} |
| 77 err := local.BuildInstance(local.BuildInstanceOptions{ | 125 err := local.BuildInstance(local.BuildInstanceOptions{ |
| 78 Input: []local.File{}, | 126 Input: []local.File{}, |
| 79 Output: &out, | 127 Output: &out, |
| 80 PackageName: "testing", | 128 PackageName: "testing", |
| 81 }) | 129 }) |
| 82 So(err, ShouldBeNil) | 130 So(err, ShouldBeNil) |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 301 |
| 254 // The file from the package should be installed. | 302 // The file from the package should be installed. |
| 255 data, err := ioutil.ReadFile(filepath.Join(tempDir, "fil
e")) | 303 data, err := ioutil.ReadFile(filepath.Join(tempDir, "fil
e")) |
| 256 So(err, ShouldBeNil) | 304 So(err, ShouldBeNil) |
| 257 So(data, ShouldResemble, []byte("test data")) | 305 So(data, ShouldResemble, []byte("test data")) |
| 258 }) | 306 }) |
| 259 }) | 307 }) |
| 260 } | 308 } |
| 261 | 309 |
| 262 func TestProcessEnsureFile(t *testing.T) { | 310 func TestProcessEnsureFile(t *testing.T) { |
| 263 » call := func(c C, data string) ([]common.Pin, error) { | 311 » call := func(c C, data string, calls []expectedHTTPCall) ([]common.Pin,
error) { |
| 264 » » client := mockClient(c, nil) | 312 » » client := mockClient(c, calls) |
| 265 return client.ProcessEnsureFile(bytes.NewBufferString(data)) | 313 return client.ProcessEnsureFile(bytes.NewBufferString(data)) |
| 266 } | 314 } |
| 267 | 315 |
| 268 Convey("ProcessEnsureFile works", t, func(c C) { | 316 Convey("ProcessEnsureFile works", t, func(c C) { |
| 269 out, err := call(c, ` | 317 out, err := call(c, ` |
| 270 # Comment | 318 # Comment |
| 271 | 319 |
| 272 pkg/a 0000000000000000000000000000000000000000 | 320 pkg/a 0000000000000000000000000000000000000000 |
| 273 pkg/b 1000000000000000000000000000000000000000 | 321 pkg/b 1000000000000000000000000000000000000000 |
| 274 » » `) | 322 » » `, nil) |
| 275 So(err, ShouldBeNil) | 323 So(err, ShouldBeNil) |
| 276 So(out, ShouldResemble, []common.Pin{ | 324 So(out, ShouldResemble, []common.Pin{ |
| 277 {"pkg/a", "0000000000000000000000000000000000000000"}, | 325 {"pkg/a", "0000000000000000000000000000000000000000"}, |
| 278 {"pkg/b", "1000000000000000000000000000000000000000"}, | 326 {"pkg/b", "1000000000000000000000000000000000000000"}, |
| 279 }) | 327 }) |
| 280 }) | 328 }) |
| 281 | 329 |
| 330 Convey("ProcessEnsureFile resolves versions", t, func(c C) { |
| 331 out, err := call(c, "pkg/a tag_key:value", []expectedHTTPCall{ |
| 332 { |
| 333 Method: "GET", |
| 334 Path: "/_ah/api/repo/v1/instance/resolve", |
| 335 Query: url.Values{ |
| 336 "package_name": []string{"pkg/a"}, |
| 337 "version": []string{"tag_key:value"
}, |
| 338 }, |
| 339 Reply: `{"status":"SUCCESS","instance_id":"00000
00000000000000000000000000000000000"}`, |
| 340 }, |
| 341 }) |
| 342 So(err, ShouldBeNil) |
| 343 So(out, ShouldResemble, []common.Pin{ |
| 344 {"pkg/a", "0000000000000000000000000000000000000000"}, |
| 345 }) |
| 346 }) |
| 347 |
| 282 Convey("ProcessEnsureFile empty", t, func(c C) { | 348 Convey("ProcessEnsureFile empty", t, func(c C) { |
| 283 » » out, err := call(c, "") | 349 » » out, err := call(c, "", nil) |
| 284 So(err, ShouldBeNil) | 350 So(err, ShouldBeNil) |
| 285 So(out, ShouldResemble, []common.Pin{}) | 351 So(out, ShouldResemble, []common.Pin{}) |
| 286 }) | 352 }) |
| 287 | 353 |
| 288 Convey("ProcessEnsureFile bad package name", t, func(c C) { | 354 Convey("ProcessEnsureFile bad package name", t, func(c C) { |
| 289 » » _, err := call(c, "bad.package.name/a 0000000000000000000000000
000000000000000") | 355 » » _, err := call(c, "bad.package.name/a 00000000000000000000000000
00000000000000", nil) |
| 290 So(err, ShouldNotBeNil) | 356 So(err, ShouldNotBeNil) |
| 291 }) | 357 }) |
| 292 | 358 |
| 293 Convey("ProcessEnsureFile bad instance ID", t, func(c C) { | 359 Convey("ProcessEnsureFile bad instance ID", t, func(c C) { |
| 294 » » _, err := call(c, "pkg/a 0000") | 360 » » _, err := call(c, "pkg/a 0000", nil) |
| 295 So(err, ShouldNotBeNil) | 361 So(err, ShouldNotBeNil) |
| 296 }) | 362 }) |
| 297 | 363 |
| 298 Convey("ProcessEnsureFile bad line", t, func(c C) { | 364 Convey("ProcessEnsureFile bad line", t, func(c C) { |
| 299 » » _, err := call(c, "pkg/a") | 365 » » _, err := call(c, "pkg/a", nil) |
| 300 So(err, ShouldNotBeNil) | 366 So(err, ShouldNotBeNil) |
| 301 }) | 367 }) |
| 302 } | 368 } |
| 303 | 369 |
| 304 func TestEnsurePackages(t *testing.T) { | 370 func TestEnsurePackages(t *testing.T) { |
| 305 Convey("Mocking temp dir", t, func() { | 371 Convey("Mocking temp dir", t, func() { |
| 306 tempDir, err := ioutil.TempDir("", "cipd_test") | 372 tempDir, err := ioutil.TempDir("", "cipd_test") |
| 307 So(err, ShouldBeNil) | 373 So(err, ShouldBeNil) |
| 308 Reset(func() { os.RemoveAll(tempDir) }) | 374 Reset(func() { os.RemoveAll(tempDir) }) |
| 309 | 375 |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 w.Header().Add(k, s) | 651 w.Header().Add(k, s) |
| 586 } | 652 } |
| 587 } | 653 } |
| 588 w.WriteHeader(exp.Status) | 654 w.WriteHeader(exp.Status) |
| 589 } | 655 } |
| 590 if exp.Reply != "" { | 656 if exp.Reply != "" { |
| 591 w.Write([]byte(exp.Reply)) | 657 w.Write([]byte(exp.Reply)) |
| 592 } | 658 } |
| 593 s.index++ | 659 s.index++ |
| 594 } | 660 } |
| OLD | NEW |