~gz/juju-core/trunk

« back to all changes in this revision

Viewing changes to charm/url_test.go

[r=rogpeppe] all: standardise gocheck imports, A-D

This is an automated change to use "gc" for gocheck
imports throughout. To avoid clogging Rietveld, I've
split it up into three parts - this is the first.

https://codereview.appspot.com/12940044/

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
        "fmt"
9
9
 
10
10
        "labix.org/v2/mgo/bson"
11
 
        . "launchpad.net/gocheck"
 
11
        gc "launchpad.net/gocheck"
12
12
 
13
13
        "launchpad.net/juju-core/charm"
14
14
)
15
15
 
16
16
type URLSuite struct{}
17
17
 
18
 
var _ = Suite(&URLSuite{})
 
18
var _ = gc.Suite(&URLSuite{})
19
19
 
20
20
var urlTests = []struct {
21
21
        s, err string
43
43
        {"local:name", "charm URL without series: .*", nil},
44
44
}
45
45
 
46
 
func (s *URLSuite) TestParseURL(c *C) {
 
46
func (s *URLSuite) TestParseURL(c *gc.C) {
47
47
        for i, t := range urlTests {
48
48
                c.Logf("test %d", i)
49
49
                url, err := charm.ParseURL(t.s)
50
 
                comment := Commentf("ParseURL(%q)", t.s)
 
50
                comment := gc.Commentf("ParseURL(%q)", t.s)
51
51
                if t.err != "" {
52
 
                        c.Check(err.Error(), Matches, t.err, comment)
 
52
                        c.Check(err.Error(), gc.Matches, t.err, comment)
53
53
                } else {
54
 
                        c.Check(url, DeepEquals, t.url, comment)
55
 
                        c.Check(t.url.String(), Equals, t.s)
 
54
                        c.Check(url, gc.DeepEquals, t.url, comment)
 
55
                        c.Check(t.url.String(), gc.Equals, t.s)
56
56
                }
57
57
        }
58
58
}
76
76
        {"cs:foo-1-2", "cs:defseries/foo-1-2"},
77
77
}
78
78
 
79
 
func (s *URLSuite) TestInferURL(c *C) {
 
79
func (s *URLSuite) TestInferURL(c *gc.C) {
80
80
        for i, t := range inferTests {
81
81
                c.Logf("test %d", i)
82
 
                comment := Commentf("InferURL(%q, %q)", t.vague, "defseries")
 
82
                comment := gc.Commentf("InferURL(%q, %q)", t.vague, "defseries")
83
83
                inferred, ierr := charm.InferURL(t.vague, "defseries")
84
84
                parsed, perr := charm.ParseURL(t.exact)
85
85
                if parsed != nil {
86
 
                        c.Check(inferred, DeepEquals, parsed, comment)
 
86
                        c.Check(inferred, gc.DeepEquals, parsed, comment)
87
87
                } else {
88
88
                        expect := perr.Error()
89
89
                        if t.vague != t.exact {
90
90
                                expect = fmt.Sprintf("%s (URL inferred from %q)", expect, t.vague)
91
91
                        }
92
 
                        c.Check(ierr.Error(), Equals, expect, comment)
 
92
                        c.Check(ierr.Error(), gc.Equals, expect, comment)
93
93
                }
94
94
        }
95
95
        u, err := charm.InferURL("~blah", "defseries")
96
 
        c.Assert(u, IsNil)
97
 
        c.Assert(err, ErrorMatches, "cannot infer charm URL with user but no schema: .*")
 
96
        c.Assert(u, gc.IsNil)
 
97
        c.Assert(err, gc.ErrorMatches, "cannot infer charm URL with user but no schema: .*")
98
98
}
99
99
 
100
100
var inferNoDefaultSeriesTests = []struct {
109
109
        {"cs:~user/series/foo", "cs:~user/series/foo"},
110
110
}
111
111
 
112
 
func (s *URLSuite) TestInferURLNoDefaultSeries(c *C) {
 
112
func (s *URLSuite) TestInferURLNoDefaultSeries(c *gc.C) {
113
113
        for _, t := range inferNoDefaultSeriesTests {
114
114
                inferred, err := charm.InferURL(t.vague, "")
115
115
                if t.exact == "" {
116
 
                        c.Assert(err, ErrorMatches, fmt.Sprintf("cannot infer charm URL for %q: no series provided", t.vague))
 
116
                        c.Assert(err, gc.ErrorMatches, fmt.Sprintf("cannot infer charm URL for %q: no series provided", t.vague))
117
117
                } else {
118
118
                        parsed, err := charm.ParseURL(t.exact)
119
 
                        c.Assert(err, IsNil)
120
 
                        c.Assert(inferred, DeepEquals, parsed, Commentf(`InferURL(%q, "")`, t.vague))
 
119
                        c.Assert(err, gc.IsNil)
 
120
                        c.Assert(inferred, gc.DeepEquals, parsed, gc.Commentf(`InferURL(%q, "")`, t.vague))
121
121
                }
122
122
        }
123
123
}
166
166
        {charm.IsValidSeries, "pre-c1se", false},
167
167
}
168
168
 
169
 
func (s *URLSuite) TestValidCheckers(c *C) {
 
169
func (s *URLSuite) TestValidCheckers(c *gc.C) {
170
170
        for i, t := range validTests {
171
171
                c.Logf("test %d: %s", i, t.string)
172
 
                c.Assert(t.valid(t.string), Equals, t.expect)
 
172
                c.Assert(t.valid(t.string), gc.Equals, t.expect)
173
173
        }
174
174
}
175
175
 
176
 
func (s *URLSuite) TestMustParseURL(c *C) {
 
176
func (s *URLSuite) TestMustParseURL(c *gc.C) {
177
177
        url := charm.MustParseURL("cs:series/name")
178
 
        c.Assert(url, DeepEquals, &charm.URL{"cs", "", "series", "name", -1})
 
178
        c.Assert(url, gc.DeepEquals, &charm.URL{"cs", "", "series", "name", -1})
179
179
        f := func() { charm.MustParseURL("local:name") }
180
 
        c.Assert(f, PanicMatches, "charm URL without series: .*")
 
180
        c.Assert(f, gc.PanicMatches, "charm URL without series: .*")
181
181
}
182
182
 
183
 
func (s *URLSuite) TestWithRevision(c *C) {
 
183
func (s *URLSuite) TestWithRevision(c *gc.C) {
184
184
        url := charm.MustParseURL("cs:series/name")
185
185
        other := url.WithRevision(1)
186
 
        c.Assert(url, DeepEquals, &charm.URL{"cs", "", "series", "name", -1})
187
 
        c.Assert(other, DeepEquals, &charm.URL{"cs", "", "series", "name", 1})
 
186
        c.Assert(url, gc.DeepEquals, &charm.URL{"cs", "", "series", "name", -1})
 
187
        c.Assert(other, gc.DeepEquals, &charm.URL{"cs", "", "series", "name", 1})
188
188
 
189
189
        // Should always copy. The opposite behavior is error prone.
190
 
        c.Assert(other.WithRevision(1), Not(Equals), other)
191
 
        c.Assert(other.WithRevision(1), DeepEquals, other)
 
190
        c.Assert(other.WithRevision(1), gc.Not(gc.Equals), other)
 
191
        c.Assert(other.WithRevision(1), gc.DeepEquals, other)
192
192
}
193
193
 
194
194
var codecs = []struct {
202
202
        Unmarshal: json.Unmarshal,
203
203
}}
204
204
 
205
 
func (s *URLSuite) TestCodecs(c *C) {
 
205
func (s *URLSuite) TestCodecs(c *gc.C) {
206
206
        for i, codec := range codecs {
207
207
                c.Logf("codec %d", i)
208
208
                type doc struct {
210
210
                }
211
211
                url := charm.MustParseURL("cs:series/name")
212
212
                data, err := codec.Marshal(doc{url})
213
 
                c.Assert(err, IsNil)
 
213
                c.Assert(err, gc.IsNil)
214
214
                var v doc
215
215
                err = codec.Unmarshal(data, &v)
216
 
                c.Assert(v.URL, DeepEquals, url)
 
216
                c.Assert(v.URL, gc.DeepEquals, url)
217
217
 
218
218
                data, err = codec.Marshal(doc{})
219
 
                c.Assert(err, IsNil)
 
219
                c.Assert(err, gc.IsNil)
220
220
                err = codec.Unmarshal(data, &v)
221
 
                c.Assert(err, IsNil)
222
 
                c.Assert(v.URL, IsNil)
 
221
                c.Assert(err, gc.IsNil)
 
222
                c.Assert(v.URL, gc.IsNil)
223
223
        }
224
224
}
225
225
 
226
226
type QuoteSuite struct{}
227
227
 
228
 
var _ = Suite(&QuoteSuite{})
 
228
var _ = gc.Suite(&QuoteSuite{})
229
229
 
230
 
func (s *QuoteSuite) TestUnmodified(c *C) {
 
230
func (s *QuoteSuite) TestUnmodified(c *gc.C) {
231
231
        // Check that a string containing only valid
232
232
        // chars stays unmodified.
233
233
        in := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-"
234
234
        out := charm.Quote(in)
235
 
        c.Assert(out, Equals, in)
 
235
        c.Assert(out, gc.Equals, in)
236
236
}
237
237
 
238
 
func (s *QuoteSuite) TestQuote(c *C) {
 
238
func (s *QuoteSuite) TestQuote(c *gc.C) {
239
239
        // Check that invalid chars are translated correctly.
240
240
        in := "hello_there/how'are~you-today.sir"
241
241
        out := charm.Quote(in)
242
 
        c.Assert(out, Equals, "hello_5f_there_2f_how_27_are_7e_you-today.sir")
 
242
        c.Assert(out, gc.Equals, "hello_5f_there_2f_how_27_are_7e_you-today.sir")
243
243
}