Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(517)

Delta Between Two Patch Sets: utils/trivial_test.go

Issue 53210044: state;apiserver: Fix a race - lp bug #1067979 (Closed)
Left Patch Set: state;apiserver: Fix a race - lp bug #1067979 Created 11 years, 1 month ago
Right Patch Set: state;apiserver: Fix a race - lp bug #1067979 Created 11 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « utils/trivial.go ('k') | worker/uniter/charm/charm.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2013 Canonical Ltd. 1 // Copyright 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package utils_test 4 package utils_test
5 5
6 import ( 6 import (
7 "bytes" 7 "bytes"
8 "fmt" 8 "fmt"
9 "io/ioutil" 9 "io/ioutil"
10 "path/filepath" 10 "path/filepath"
(...skipping 22 matching lines...) Expand all
33 0x08, 0x45, 0xc1, 0xde, 0x29, 0x58, 0x0d, 0xe5, 33 0x08, 0x45, 0xc1, 0xde, 0x29, 0x58, 0x0d, 0xe5,
34 0x97, 0x04, 0x23, 0xee, 0x1f, 0xa7, 0xb0, 0x7b, 34 0x97, 0x04, 0x23, 0xee, 0x1f, 0xa7, 0xb0, 0x7b,
35 0xd7, 0x5e, 0x57, 0xca, 0xc2, 0xaf, 0xdb, 0x2d, 35 0xd7, 0x5e, 0x57, 0xca, 0xc2, 0xaf, 0xdb, 0x2d,
36 0x9b, 0xb2, 0x55, 0xb9, 0x8f, 0xba, 0x15, 0xa3, 36 0x9b, 0xb2, 0x55, 0xb9, 0x8f, 0xba, 0x15, 0xa3,
37 0x29, 0x8a, 0xa2, 0x28, 0x8a, 0xa2, 0x28, 0xea, 37 0x29, 0x8a, 0xa2, 0x28, 0x8a, 0xa2, 0x28, 0xea,
38 0x67, 0x3d, 0x71, 0x71, 0x6e, 0xbf, 0x8c, 0x0a, 38 0x67, 0x3d, 0x71, 0x71, 0x6e, 0xbf, 0x8c, 0x0a,
39 0x00, 0x00, 39 0x00, 0x00,
40 } 40 }
41 ) 41 )
42 42
43 func (utilsSuite) TestCompression(c *gc.C) { 43 func (*utilsSuite) TestCompression(c *gc.C) {
44 cdata := utils.Gzip(data) 44 cdata := utils.Gzip(data)
45 c.Assert(len(cdata) < len(data), gc.Equals, true) 45 c.Assert(len(cdata) < len(data), gc.Equals, true)
46 data1, err := utils.Gunzip(cdata) 46 data1, err := utils.Gunzip(cdata)
47 c.Assert(err, gc.IsNil) 47 c.Assert(err, gc.IsNil)
48 c.Assert(data1, gc.DeepEquals, data) 48 c.Assert(data1, gc.DeepEquals, data)
49 49
50 data1, err = utils.Gunzip(compressedData) 50 data1, err = utils.Gunzip(compressedData)
51 c.Assert(err, gc.IsNil) 51 c.Assert(err, gc.IsNil)
52 c.Assert(data1, gc.DeepEquals, data) 52 c.Assert(data1, gc.DeepEquals, data)
53 } 53 }
54 54
55 func (utilsSuite) TestCommandString(c *gc.C) { 55 func (*utilsSuite) TestCommandString(c *gc.C) {
56 type test struct { 56 type test struct {
57 args []string 57 args []string
58 expected string 58 expected string
59 } 59 }
60 tests := []test{ 60 tests := []test{
61 {nil, ""}, 61 {nil, ""},
62 {[]string{"a"}, "a"}, 62 {[]string{"a"}, "a"},
63 {[]string{"a$"}, `"a\$"`}, 63 {[]string{"a$"}, `"a\$"`},
64 {[]string{""}, ""}, 64 {[]string{""}, ""},
65 {[]string{"\\"}, `"\\"`}, 65 {[]string{"\\"}, `"\\"`},
66 {[]string{"a", "'b'"}, "a 'b'"}, 66 {[]string{"a", "'b'"}, "a 'b'"},
67 {[]string{"a b"}, `"a b"`}, 67 {[]string{"a b"}, `"a b"`},
68 {[]string{"a", `"b"`}, `a "\"b\""`}, 68 {[]string{"a", `"b"`}, `a "\"b\""`},
69 {[]string{"a", `"b\"`}, `a "\"b\\\""`}, 69 {[]string{"a", `"b\"`}, `a "\"b\\\""`},
70 {[]string{"a\n"}, "\"a\n\""}, 70 {[]string{"a\n"}, "\"a\n\""},
71 } 71 }
72 for i, test := range tests { 72 for i, test := range tests {
73 c.Logf("test %d: %q", i, test.args) 73 c.Logf("test %d: %q", i, test.args)
74 result := utils.CommandString(test.args...) 74 result := utils.CommandString(test.args...)
75 c.Assert(result, gc.Equals, test.expected) 75 c.Assert(result, gc.Equals, test.expected)
76 } 76 }
77 } 77 }
78 78
79 var sha256Tests = []struct { 79 func (*utilsSuite) TestReadSHA256AndReadFileSHA256(c *gc.C) {
80 » content string 80 » sha256Tests := []struct {
81 » sha256 string 81 » » content string
82 }{ 82 » » sha256 string
83 » { 83 » }{{
84 content: "", 84 content: "",
85 sha256: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca49599 1b7852b855", 85 sha256: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca49599 1b7852b855",
86 » }, 86 » }, {
87 » {
fwereade 2014/01/29 16:01:22 }{{ ... },{ ... to compress both vertical
dimitern 2014/01/29 20:59:13 Done.
88 content: "some content", 87 content: "some content",
89 sha256: "290f493c44f5d63d06b374d0a5abd292fae38b92cab2fae5efefe1 b0e9347f56", 88 sha256: "290f493c44f5d63d06b374d0a5abd292fae38b92cab2fae5efefe1 b0e9347f56",
90 » }, 89 » }, {
91 » {
92 content: "foo", 90 content: "foo",
93 sha256: "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e 886266e7ae", 91 sha256: "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e 886266e7ae",
94 » }, 92 » }, {
95 » {
96 content: "Foo", 93 content: "Foo",
97 sha256: "1cbec737f863e4922cee63cc2ebbfaafcd1cff8b790d8cfd2e6a5d 550b648afa", 94 sha256: "1cbec737f863e4922cee63cc2ebbfaafcd1cff8b790d8cfd2e6a5d 550b648afa",
98 » }, 95 » }, {
99 » {
100 content: "multi\nline\ntext\nhere", 96 content: "multi\nline\ntext\nhere",
101 sha256: "c384f11c0294280792a44d9d6abb81f9fd991904cb7eb851a88311 b04114231e", 97 sha256: "c384f11c0294280792a44d9d6abb81f9fd991904cb7eb851a88311 b04114231e",
102 » }, 98 » }}
103 }
104 99
105 func (utilsSuite) TestReadSHA256AndReadFileSHA256(c *gc.C) {
fwereade 2014/01/29 16:01:22 *utilsSuite, please, across the board, lest someon
dimitern 2014/01/29 20:59:13 Done.
106 tempDir := c.MkDir() 100 tempDir := c.MkDir()
107 for i, test := range sha256Tests { 101 for i, test := range sha256Tests {
108 c.Logf("test %d: %q -> %q", i, test.content, test.sha256) 102 c.Logf("test %d: %q -> %q", i, test.content, test.sha256)
109 buf := bytes.NewBufferString(test.content) 103 buf := bytes.NewBufferString(test.content)
110 hash, size, err := utils.ReadSHA256(buf) 104 hash, size, err := utils.ReadSHA256(buf)
111 c.Check(err, gc.IsNil) 105 c.Check(err, gc.IsNil)
112 c.Check(hash, gc.Equals, test.sha256) 106 c.Check(hash, gc.Equals, test.sha256)
113 c.Check(int(size), gc.Equals, len(test.content)) 107 c.Check(int(size), gc.Equals, len(test.content))
114 108
115 tempFileName := filepath.Join(tempDir, fmt.Sprintf("sha256-%d", i)) 109 tempFileName := filepath.Join(tempDir, fmt.Sprintf("sha256-%d", i))
116 err = ioutil.WriteFile(tempFileName, []byte(test.content), 0644) 110 err = ioutil.WriteFile(tempFileName, []byte(test.content), 0644)
117 c.Check(err, gc.IsNil) 111 c.Check(err, gc.IsNil)
118 fileHash, fileSize, err := utils.ReadFileSHA256(tempFileName) 112 fileHash, fileSize, err := utils.ReadFileSHA256(tempFileName)
119 c.Check(err, gc.IsNil) 113 c.Check(err, gc.IsNil)
120 c.Check(fileHash, gc.Equals, hash) 114 c.Check(fileHash, gc.Equals, hash)
121 c.Check(fileSize, gc.Equals, size) 115 c.Check(fileSize, gc.Equals, size)
122 } 116 }
123 } 117 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b