Skip to content

Commit dd855ce

Browse files
committed
Use external HTTPSuite.
1 parent b99c0ba commit dd855ce

File tree

7 files changed

+54
-246
lines changed

7 files changed

+54
-246
lines changed

cmd/juju/publish_test.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
type PublishSuite struct {
2323
testing.FakeJujuHomeSuite
24-
testing.HTTPSuite
24+
gitjujutesting.HTTPSuite
2525

2626
dir string
2727
oldBaseURL string
@@ -172,13 +172,13 @@ func (s *PublishSuite) TestPreExistingPublished(c *gc.C) {
172172
digest, err := s.branch.RevisionId()
173173
c.Assert(err, gc.IsNil)
174174
body := `{"cs:precise/wordpress": {"kind": "published", "digest": %q, "revision": 42}}`
175-
testing.Server.Response(200, nil, []byte(fmt.Sprintf(body, digest)))
175+
gitjujutesting.Server.Response(200, nil, []byte(fmt.Sprintf(body, digest)))
176176

177177
ctx, err := s.runPublish(c, "cs:precise/wordpress")
178178
c.Assert(err, gc.IsNil)
179179
c.Assert(testing.Stdout(ctx), gc.Equals, "cs:precise/wordpress-42\n")
180180

181-
req := testing.Server.WaitRequest()
181+
req := gitjujutesting.Server.WaitRequest()
182182
c.Assert(req.URL.Path, gc.Equals, "/charm-event")
183183
c.Assert(req.Form.Get("charms"), gc.Equals, "cs:precise/wordpress@"+digest)
184184
}
@@ -194,19 +194,19 @@ func (s *PublishSuite) TestPreExistingPublishedEdge(c *gc.C) {
194194
c.Assert(err, gc.IsNil)
195195
var body string
196196
body = `{"cs:precise/wordpress": {"errors": ["entry not found"]}}`
197-
testing.Server.Response(200, nil, []byte(body))
197+
gitjujutesting.Server.Response(200, nil, []byte(body))
198198
body = `{"cs:precise/wordpress": {"kind": "published", "digest": %q, "revision": 42}}`
199-
testing.Server.Response(200, nil, []byte(fmt.Sprintf(body, digest)))
199+
gitjujutesting.Server.Response(200, nil, []byte(fmt.Sprintf(body, digest)))
200200

201201
ctx, err := s.runPublish(c, "cs:precise/wordpress")
202202
c.Assert(err, gc.IsNil)
203203
c.Assert(testing.Stdout(ctx), gc.Equals, "cs:precise/wordpress-42\n")
204204

205-
req := testing.Server.WaitRequest()
205+
req := gitjujutesting.Server.WaitRequest()
206206
c.Assert(req.URL.Path, gc.Equals, "/charm-event")
207207
c.Assert(req.Form.Get("charms"), gc.Equals, "cs:precise/wordpress@"+digest)
208208

209-
req = testing.Server.WaitRequest()
209+
req = gitjujutesting.Server.WaitRequest()
210210
c.Assert(req.URL.Path, gc.Equals, "/charm-event")
211211
c.Assert(req.Form.Get("charms"), gc.Equals, "cs:precise/wordpress")
212212
}
@@ -218,12 +218,12 @@ func (s *PublishSuite) TestPreExistingPublishError(c *gc.C) {
218218
digest, err := s.branch.RevisionId()
219219
c.Assert(err, gc.IsNil)
220220
body := `{"cs:precise/wordpress": {"kind": "publish-error", "digest": %q, "errors": ["an error"]}}`
221-
testing.Server.Response(200, nil, []byte(fmt.Sprintf(body, digest)))
221+
gitjujutesting.Server.Response(200, nil, []byte(fmt.Sprintf(body, digest)))
222222

223223
_, err = s.runPublish(c, "cs:precise/wordpress")
224224
c.Assert(err, gc.ErrorMatches, "charm could not be published: an error")
225225

226-
req := testing.Server.WaitRequest()
226+
req := gitjujutesting.Server.WaitRequest()
227227
c.Assert(req.URL.Path, gc.Equals, "/charm-event")
228228
c.Assert(req.Form.Get("charms"), gc.Equals, "cs:precise/wordpress@"+digest)
229229
}
@@ -249,19 +249,19 @@ func (s *PublishSuite) TestFullPublish(c *gc.C) {
249249

250250
// The local digest isn't found.
251251
body = `{"cs:~user/precise/wordpress": {"kind": "", "errors": ["entry not found"]}}`
252-
testing.Server.Response(200, nil, []byte(body))
252+
gitjujutesting.Server.Response(200, nil, []byte(body))
253253

254254
// But the charm exists with an arbitrary non-matching digest.
255255
body = `{"cs:~user/precise/wordpress": {"kind": "published", "digest": "other-digest"}}`
256-
testing.Server.Response(200, nil, []byte(body))
256+
gitjujutesting.Server.Response(200, nil, []byte(body))
257257

258258
// After the branch is pushed we fake the publishing delay.
259259
body = `{"cs:~user/precise/wordpress": {"kind": "published", "digest": "other-digest"}}`
260-
testing.Server.Response(200, nil, []byte(body))
260+
gitjujutesting.Server.Response(200, nil, []byte(body))
261261

262262
// And finally report success.
263263
body = `{"cs:~user/precise/wordpress": {"kind": "published", "digest": %q, "revision": 42}}`
264-
testing.Server.Response(200, nil, []byte(fmt.Sprintf(body, digest)))
264+
gitjujutesting.Server.Response(200, nil, []byte(fmt.Sprintf(body, digest)))
265265

266266
ctx, err := testing.RunCommandInDir(c, envcmd.Wrap(cmd), []string{"cs:~user/precise/wordpress"}, s.dir)
267267
c.Assert(err, gc.IsNil)
@@ -273,14 +273,14 @@ func (s *PublishSuite) TestFullPublish(c *gc.C) {
273273
c.Assert(pushDigest, gc.Equals, digest)
274274

275275
// And that all the requests were sent with the proper data.
276-
req := testing.Server.WaitRequest()
276+
req := gitjujutesting.Server.WaitRequest()
277277
c.Assert(req.URL.Path, gc.Equals, "/charm-event")
278278
c.Assert(req.Form.Get("charms"), gc.Equals, "cs:~user/precise/wordpress@"+digest)
279279

280280
for i := 0; i < 3; i++ {
281281
// The second request grabs tip to see the current state, and the
282282
// following requests are done after pushing to see when it changes.
283-
req = testing.Server.WaitRequest()
283+
req = gitjujutesting.Server.WaitRequest()
284284
c.Assert(req.URL.Path, gc.Equals, "/charm-event")
285285
c.Assert(req.Form.Get("charms"), gc.Equals, "cs:~user/precise/wordpress")
286286
}
@@ -307,17 +307,17 @@ func (s *PublishSuite) TestFullPublishError(c *gc.C) {
307307

308308
// The local digest isn't found.
309309
body = `{"cs:~user/precise/wordpress": {"kind": "", "errors": ["entry not found"]}}`
310-
testing.Server.Response(200, nil, []byte(body))
310+
gitjujutesting.Server.Response(200, nil, []byte(body))
311311

312312
// And tip isn't found either, meaning the charm was never published.
313-
testing.Server.Response(200, nil, []byte(body))
313+
gitjujutesting.Server.Response(200, nil, []byte(body))
314314

315315
// After the branch is pushed we fake the publishing delay.
316-
testing.Server.Response(200, nil, []byte(body))
316+
gitjujutesting.Server.Response(200, nil, []byte(body))
317317

318318
// And finally report success.
319319
body = `{"cs:~user/precise/wordpress": {"kind": "published", "digest": %q, "revision": 42}}`
320-
testing.Server.Response(200, nil, []byte(fmt.Sprintf(body, digest)))
320+
gitjujutesting.Server.Response(200, nil, []byte(fmt.Sprintf(body, digest)))
321321

322322
ctx, err := testing.RunCommandInDir(c, envcmd.Wrap(cmd), []string{"cs:~user/precise/wordpress"}, s.dir)
323323
c.Assert(err, gc.IsNil)
@@ -329,14 +329,14 @@ func (s *PublishSuite) TestFullPublishError(c *gc.C) {
329329
c.Assert(pushDigest, gc.Equals, digest)
330330

331331
// And that all the requests were sent with the proper data.
332-
req := testing.Server.WaitRequest()
332+
req := gitjujutesting.Server.WaitRequest()
333333
c.Assert(req.URL.Path, gc.Equals, "/charm-event")
334334
c.Assert(req.Form.Get("charms"), gc.Equals, "cs:~user/precise/wordpress@"+digest)
335335

336336
for i := 0; i < 3; i++ {
337337
// The second request grabs tip to see the current state, and the
338338
// following requests are done after pushing to see when it changes.
339-
req = testing.Server.WaitRequest()
339+
req = gitjujutesting.Server.WaitRequest()
340340
c.Assert(req.URL.Path, gc.Equals, "/charm-event")
341341
c.Assert(req.Form.Get("charms"), gc.Equals, "cs:~user/precise/wordpress")
342342
}
@@ -363,17 +363,17 @@ func (s *PublishSuite) TestFullPublishRace(c *gc.C) {
363363

364364
// The local digest isn't found.
365365
body = `{"cs:~user/precise/wordpress": {"kind": "", "errors": ["entry not found"]}}`
366-
testing.Server.Response(200, nil, []byte(body))
366+
gitjujutesting.Server.Response(200, nil, []byte(body))
367367

368368
// And tip isn't found either, meaning the charm was never published.
369-
testing.Server.Response(200, nil, []byte(body))
369+
gitjujutesting.Server.Response(200, nil, []byte(body))
370370

371371
// After the branch is pushed we fake the publishing delay.
372-
testing.Server.Response(200, nil, []byte(body))
372+
gitjujutesting.Server.Response(200, nil, []byte(body))
373373

374374
// But, surprisingly, the digest changed to something else entirely.
375375
body = `{"cs:~user/precise/wordpress": {"kind": "published", "digest": "surprising-digest", "revision": 42}}`
376-
testing.Server.Response(200, nil, []byte(body))
376+
gitjujutesting.Server.Response(200, nil, []byte(body))
377377

378378
_, err = testing.RunCommandInDir(c, envcmd.Wrap(cmd), []string{"cs:~user/precise/wordpress"}, s.dir)
379379
c.Assert(err, gc.ErrorMatches, `charm changed but not to local charm digest; publishing race\?`)
@@ -384,14 +384,14 @@ func (s *PublishSuite) TestFullPublishRace(c *gc.C) {
384384
c.Assert(pushDigest, gc.Equals, digest)
385385

386386
// And that all the requests were sent with the proper data.
387-
req := testing.Server.WaitRequest()
387+
req := gitjujutesting.Server.WaitRequest()
388388
c.Assert(req.URL.Path, gc.Equals, "/charm-event")
389389
c.Assert(req.Form.Get("charms"), gc.Equals, "cs:~user/precise/wordpress@"+digest)
390390

391391
for i := 0; i < 3; i++ {
392392
// The second request grabs tip to see the current state, and the
393393
// following requests are done after pushing to see when it changes.
394-
req = testing.Server.WaitRequest()
394+
req = gitjujutesting.Server.WaitRequest()
395395
c.Assert(req.URL.Path, gc.Equals, "/charm-event")
396396
c.Assert(req.Form.Get("charms"), gc.Equals, "cs:~user/precise/wordpress")
397397
}

downloader/downloader_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
stdtesting "testing"
1111
"time"
1212

13+
gitjujutesting "github.com/juju/testing"
1314
"github.com/juju/utils"
1415
gc "launchpad.net/gocheck"
1516

@@ -19,7 +20,7 @@ import (
1920

2021
type suite struct {
2122
testing.BaseSuite
22-
testing.HTTPSuite
23+
gitjujutesting.HTTPSuite
2324
}
2425

2526
func (s *suite) SetUpSuite(c *gc.C) {
@@ -50,7 +51,7 @@ func Test(t *stdtesting.T) {
5051

5152
func (s *suite) testDownload(c *gc.C, hostnameVerification utils.SSLHostnameVerification) {
5253
tmp := c.MkDir()
53-
testing.Server.Response(200, nil, []byte("archive"))
54+
gitjujutesting.Server.Response(200, nil, []byte("archive"))
5455
d := downloader.New(s.URL("/archive.tgz"), tmp, hostnameVerification)
5556
status := <-d.Done()
5657
c.Assert(status.Err, gc.IsNil)
@@ -72,7 +73,7 @@ func (s *suite) TestDownloadWithDisablingSSLHostnameVerification(c *gc.C) {
7273
}
7374

7475
func (s *suite) TestDownloadError(c *gc.C) {
75-
testing.Server.Response(404, nil, nil)
76+
gitjujutesting.Server.Response(404, nil, nil)
7677
d := downloader.New(s.URL("/archive.tgz"), c.MkDir(), utils.VerifySSLHostnames)
7778
status := <-d.Done()
7879
c.Assert(status.File, gc.IsNil)

store/lpad_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package store_test
66
import (
77
"fmt"
88

9+
gitjujutesting "github.com/juju/testing"
910
gc "launchpad.net/gocheck"
1011
"launchpad.net/lpad"
1112

@@ -22,7 +23,7 @@ func (s *StoreSuite) TestPublishCharmDistro(c *gc.C) {
2223
branch := s.dummyBranch(c, "~joe/charms/oneiric/dummy/trunk")
2324

2425
// The Distro call will look for bare /charms, first.
25-
testing.Server.Response(200, jsonType, []byte("{}"))
26+
gitjujutesting.Server.Response(200, jsonType, []byte("{}"))
2627

2728
// And then it picks up the tips.
2829
data := fmt.Sprintf(`[`+
@@ -32,9 +33,9 @@ func (s *StoreSuite) TestPublishCharmDistro(c *gc.C) {
3233
`["file:///non-existent/~jeff/charms/precise/bad/skip-me", "rev3", []]`+
3334
`]`,
3435
branch.path(), branch.path(), branch.digest())
35-
testing.Server.Response(200, jsonType, []byte(data))
36+
gitjujutesting.Server.Response(200, jsonType, []byte(data))
3637

37-
apiBase := lpad.APIBase(testing.Server.URL)
38+
apiBase := lpad.APIBase(gitjujutesting.Server.URL)
3839
err := store.PublishCharmsDistro(s.store, apiBase)
3940

4041
// Should have a single failure from the trunk branch that doesn't
@@ -57,12 +58,12 @@ func (s *StoreSuite) TestPublishCharmDistro(c *gc.C) {
5758
c.Assert(err, gc.Equals, store.ErrNotFound)
5859

5960
// bare /charms lookup
60-
req := testing.Server.WaitRequest()
61+
req := gitjujutesting.Server.WaitRequest()
6162
c.Assert(req.Method, gc.Equals, "GET")
6263
c.Assert(req.URL.Path, gc.Equals, "/charms")
6364

6465
// tips request
65-
req = testing.Server.WaitRequest()
66+
req = gitjujutesting.Server.WaitRequest()
6667
c.Assert(req.Method, gc.Equals, "GET")
6768
c.Assert(req.URL.Path, gc.Equals, "/charms")
6869
c.Assert(req.Form["ws.op"], gc.DeepEquals, []string{"getBranchTips"})

store/store_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var _ = gc.Suite(&TrivialSuite{})
3333

3434
type StoreSuite struct {
3535
gitjujutesting.MgoSuite
36-
testing.HTTPSuite
36+
gitjujutesting.HTTPSuite
3737
gitjujutesting.FakeHomeSuite
3838
store *store.Store
3939
}

0 commit comments

Comments
 (0)