Merge lp:~rvb/gwacl/testing-utility into lp:gwacl

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: 112
Merged at revision: 112
Proposed branch: lp:~rvb/gwacl/testing-utility
Merge into: lp:gwacl
Diff against target: 52 lines (+43/-0)
2 files modified
testing.go (+18/-0)
testing_test.go (+25/-0)
To merge this branch: bzr merge lp:~rvb/gwacl/testing-utility
Reviewer Review Type Date Requested Status
Gavin Panella Approve
Review via email: mp+170078@code.launchpad.net

Commit message

Add testing utility.

Description of the change

This utility is there to let libraries using gwacl (for instance the Azure provider in juju-core) create testing StorageContext objects.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

[1]

+func CreateTestStorageContext(client *http.Client) *StorageContext {

The prefix is usually "New" in Go instead of "Create". I'm not bothered either way, as long as it's consistent with what's there already, or, failing that, consistent with Go convention.

review: Approve
lp:~rvb/gwacl/testing-utility updated
112. By Raphaël Badin

Review fixes.

Revision history for this message
Raphaël Badin (rvb) wrote :

> [1]
>
> +func CreateTestStorageContext(client *http.Client) *StorageContext {
>
> The prefix is usually "New" in Go instead of "Create". I'm not bothered either
> way, as long as it's consistent with what's there already, or, failing that,
> consistent with Go convention.

Good point, fixed.

Revision history for this message
Julian Edwards (julian-edwards) wrote :

On 18/06/13 23:43, Raphaël Badin wrote:
>
> === added file 'testing.go'

This needs to be of the form XXXXX_test.go, because otherwise it's going
to get compiled into a final build instead of being restricted to test code.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'testing.go'
2--- testing.go 1970-01-01 00:00:00 +0000
3+++ testing.go 2013-06-18 13:53:26 +0000
4@@ -0,0 +1,18 @@
5+// Copyright 2013 Canonical Ltd. This software is licensed under the
6+// GNU Lesser General Public License version 3 (see the file COPYING).
7+
8+package gwacl
9+
10+import (
11+ "net/http"
12+)
13+
14+// NewTestStorageContext returns a StorageContext object built using
15+// the given *http.Client object. It's meant to be used in the tests
16+// of other libraries using gwacl to create a StorageContext that will
17+// interact with a fake client object.
18+func NewTestStorageContext(client *http.Client) *StorageContext {
19+ storageContext := &StorageContext{}
20+ storageContext.client = client
21+ return storageContext
22+}
23
24=== added file 'testing_test.go'
25--- testing_test.go 1970-01-01 00:00:00 +0000
26+++ testing_test.go 2013-06-18 13:53:26 +0000
27@@ -0,0 +1,25 @@
28+// Copyright 2013 Canonical Ltd. This software is licensed under the
29+// GNU Lesser General Public License version 3 (see the file COPYING).
30+
31+package gwacl
32+
33+import (
34+ "fmt"
35+ . "launchpad.net/gocheck"
36+ "net/http"
37+)
38+
39+type testTesting struct{}
40+
41+var _ = Suite(&testTesting{})
42+
43+func (suite *testTesting) TestNewTestStorageContext(c *C) {
44+ errorMessage := "canned-error"
45+ error := fmt.Errorf(errorMessage)
46+ transport := &TestTransport{Error: error}
47+ client := &http.Client{Transport: transport}
48+ context := NewTestStorageContext(client)
49+ request := &ListContainersRequest{Marker: ""}
50+ _, err := context.ListContainers(request)
51+ c.Check(err, ErrorMatches, ".*"+errorMessage+".*")
52+}

Subscribers

People subscribed via source and target branches

to all changes: