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

Side by Side Diff: go/src/infra/tools/cipd/common/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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 common
6 6
7 import ( 7 import (
8 » "bytes" 8 » "fmt"
9 "strings" 9 "strings"
10 "testing" 10 "testing"
11 11
12 . "github.com/smartystreets/goconvey/convey" 12 . "github.com/smartystreets/goconvey/convey"
13 ) 13 )
14 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) { 15 func TestValidatePackageName(t *testing.T) {
48 Convey("ValidatePackageName works", t, func() { 16 Convey("ValidatePackageName works", t, func() {
49 So(ValidatePackageName("good/name"), ShouldBeNil) 17 So(ValidatePackageName("good/name"), ShouldBeNil)
50 So(ValidatePackageName("good_name"), ShouldBeNil) 18 So(ValidatePackageName("good_name"), ShouldBeNil)
51 So(ValidatePackageName("123-_/also/good/name"), ShouldBeNil) 19 So(ValidatePackageName("123-_/also/good/name"), ShouldBeNil)
52 So(ValidatePackageName(""), ShouldNotBeNil) 20 So(ValidatePackageName(""), ShouldNotBeNil)
53 So(ValidatePackageName("BAD/name"), ShouldNotBeNil) 21 So(ValidatePackageName("BAD/name"), ShouldNotBeNil)
54 So(ValidatePackageName("bad//name"), ShouldNotBeNil) 22 So(ValidatePackageName("bad//name"), ShouldNotBeNil)
55 So(ValidatePackageName("bad/name/"), ShouldNotBeNil) 23 So(ValidatePackageName("bad/name/"), ShouldNotBeNil)
56 So(ValidatePackageName("bad.name"), ShouldNotBeNil) 24 So(ValidatePackageName("bad.name"), ShouldNotBeNil)
(...skipping 21 matching lines...) Expand all
78 So(ValidateInstanceTag(""), ShouldNotBeNil) 46 So(ValidateInstanceTag(""), ShouldNotBeNil)
79 So(ValidateInstanceTag("notapair"), ShouldNotBeNil) 47 So(ValidateInstanceTag("notapair"), ShouldNotBeNil)
80 So(ValidateInstanceTag(strings.Repeat("long", 200)+":abc"), Shou ldNotBeNil) 48 So(ValidateInstanceTag(strings.Repeat("long", 200)+":abc"), Shou ldNotBeNil)
81 So(ValidateInstanceTag("BADKEY:value"), ShouldNotBeNil) 49 So(ValidateInstanceTag("BADKEY:value"), ShouldNotBeNil)
82 So(ValidateInstanceTag("good:tag"), ShouldBeNil) 50 So(ValidateInstanceTag("good:tag"), ShouldBeNil)
83 So(ValidateInstanceTag("good_tag:"), ShouldBeNil) 51 So(ValidateInstanceTag("good_tag:"), ShouldBeNil)
84 So(ValidateInstanceTag("good:tag:blah"), ShouldBeNil) 52 So(ValidateInstanceTag("good:tag:blah"), ShouldBeNil)
85 So(ValidateInstanceTag("good_tag:asdad/asdad/adad/a\\asdasdad"), ShouldBeNil) 53 So(ValidateInstanceTag("good_tag:asdad/asdad/adad/a\\asdasdad"), ShouldBeNil)
86 }) 54 })
87 } 55 }
56
57 func TestValidatePin(t *testing.T) {
58 Convey("TestValidatePin works", t, func() {
59 So(ValidatePin(Pin{"good/name", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaa"}), ShouldBeNil)
60 So(ValidatePin(Pin{"BAD/name", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaa"}), ShouldNotBeNil)
61 So(ValidatePin(Pin{"good/name", "aaaaaaaaaaa"}), ShouldNotBeNil)
62 })
63 }
64
65 func TestPinToString(t *testing.T) {
66 Convey("Pin.String works", t, func() {
67 So(
68 fmt.Sprintf("%s", Pin{"good/name", "aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa"}),
69 ShouldEqual,
70 "good/name:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
71 })
72 }
OLDNEW
« no previous file with comments | « go/src/infra/tools/cipd/common/common.infra_testing ('k') | go/src/infra/tools/cipd/common_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698