Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(398)

Side by Side Diff: go/src/infra/tools/cipd/common_test.go

Issue 1129043003: cipd: Refactor client to make it more readable. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « go/src/infra/tools/cipd/common/common_test.go ('k') | go/src/infra/tools/cipd/deployer.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package cipd
6
7 import (
8 "bytes"
9 "strings"
10 "testing"
11
12 . "github.com/smartystreets/goconvey/convey"
13 )
14
15 func TestReadManifest(t *testing.T) {
16 var goodManifest = `{
17 "format_version": "1",
18 "package_name": "package/name"
19 }`
20
21 Convey("readManifest can read valid manifest", t, func() {
22 manifest, err := readManifest(strings.NewReader(goodManifest))
23 So(manifest, ShouldResemble, Manifest{
24 FormatVersion: "1",
25 PackageName: "package/name",
26 })
27 So(err, ShouldBeNil)
28 })
29
30 Convey("readManifest rejects invalid manifest", t, func() {
31 manifest, err := readManifest(strings.NewReader("I'm not a manif est"))
32 So(manifest, ShouldResemble, Manifest{})
33 So(err, ShouldNotBeNil)
34 })
35
36 Convey("writeManifest works", t, func() {
37 buf := &bytes.Buffer{}
38 m := Manifest{
39 FormatVersion: "1",
40 PackageName: "package/name",
41 }
42 So(writeManifest(&m, buf), ShouldBeNil)
43 So(string(buf.Bytes()), ShouldEqual, goodManifest)
44 })
45 }
46
47 func TestValidatePackageName(t *testing.T) {
48 Convey("ValidatePackageName works", t, func() {
49 So(ValidatePackageName("good/name"), ShouldBeNil)
50 So(ValidatePackageName("good_name"), ShouldBeNil)
51 So(ValidatePackageName("123-_/also/good/name"), ShouldBeNil)
52 So(ValidatePackageName(""), ShouldNotBeNil)
53 So(ValidatePackageName("BAD/name"), ShouldNotBeNil)
54 So(ValidatePackageName("bad//name"), ShouldNotBeNil)
55 So(ValidatePackageName("bad/name/"), ShouldNotBeNil)
56 So(ValidatePackageName("bad.name"), ShouldNotBeNil)
57 So(ValidatePackageName("/bad/name"), ShouldNotBeNil)
58 So(ValidatePackageName("bad/name\nyeah"), ShouldNotBeNil)
59 So(ValidatePackageName("../../yeah"), ShouldNotBeNil)
60 })
61 }
62
63 func TestValidateInstanceID(t *testing.T) {
64 Convey("ValidateInstanceID works", t, func() {
65 So(ValidateInstanceID(""), ShouldNotBeNil)
66 So(ValidateInstanceID("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ), ShouldBeNil)
67 So(ValidateInstanceID("0123456789abcdefaaaaaaaaaaaaaaaaaaaaaaaa" ), ShouldBeNil)
68 So(ValidateInstanceID("€aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ), ShouldNotBeNil)
69 So(ValidateInstanceID("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") , ShouldNotBeNil)
70 So(ValidateInstanceID("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa "), ShouldNotBeNil)
71 So(ValidateInstanceID("gaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ), ShouldNotBeNil)
72 So(ValidateInstanceID("AAAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ), ShouldNotBeNil)
73 })
74 }
75
76 func TestValidateInstanceTag(t *testing.T) {
77 Convey("ValidateInstanceTag works", t, func() {
78 So(ValidateInstanceTag(""), ShouldNotBeNil)
79 So(ValidateInstanceTag("notapair"), ShouldNotBeNil)
80 So(ValidateInstanceTag(strings.Repeat("long", 200)+":abc"), Shou ldNotBeNil)
81 So(ValidateInstanceTag("BADKEY:value"), ShouldNotBeNil)
82 So(ValidateInstanceTag("good:tag"), ShouldBeNil)
83 So(ValidateInstanceTag("good_tag:"), ShouldBeNil)
84 So(ValidateInstanceTag("good:tag:blah"), ShouldBeNil)
85 So(ValidateInstanceTag("good_tag:asdad/asdad/adad/a\\asdasdad"), ShouldBeNil)
86 })
87 }
OLDNEW
« no previous file with comments | « go/src/infra/tools/cipd/common/common_test.go ('k') | go/src/infra/tools/cipd/deployer.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698