Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit 07400f3

Browse files
committed
Reorganized volumes and volumeattach to move fixtures to subpackage
1 parent 1d8b6f1 commit 07400f3

File tree

8 files changed

+100
-54
lines changed

8 files changed

+100
-54
lines changed

openstack/blockstorage/v1/volumes/requests_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package volumes
33
import (
44
"testing"
55

6+
fixtures "github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes/testing"
67
"github.com/rackspace/gophercloud/pagination"
78
th "github.com/rackspace/gophercloud/testhelper"
89
"github.com/rackspace/gophercloud/testhelper/client"
@@ -12,7 +13,7 @@ func TestList(t *testing.T) {
1213
th.SetupHTTP()
1314
defer th.TeardownHTTP()
1415

15-
MockListResponse(t)
16+
fixtures.MockListResponse(t)
1617

1718
count := 0
1819

@@ -49,7 +50,7 @@ func TestListAll(t *testing.T) {
4950
th.SetupHTTP()
5051
defer th.TeardownHTTP()
5152

52-
MockListResponse(t)
53+
fixtures.MockListResponse(t)
5354

5455
allPages, err := List(client.ServiceClient(), &ListOpts{}).AllPages()
5556
th.AssertNoErr(t, err)
@@ -75,7 +76,7 @@ func TestGet(t *testing.T) {
7576
th.SetupHTTP()
7677
defer th.TeardownHTTP()
7778

78-
MockGetResponse(t)
79+
fixtures.MockGetResponse(t)
7980

8081
v, err := Get(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22").Extract()
8182
th.AssertNoErr(t, err)
@@ -89,7 +90,7 @@ func TestCreate(t *testing.T) {
8990
th.SetupHTTP()
9091
defer th.TeardownHTTP()
9192

92-
MockCreateResponse(t)
93+
fixtures.MockCreateResponse(t)
9394

9495
options := &CreateOpts{Size: 75}
9596
n, err := Create(client.ServiceClient(), options).Extract()
@@ -103,7 +104,7 @@ func TestDelete(t *testing.T) {
103104
th.SetupHTTP()
104105
defer th.TeardownHTTP()
105106

106-
MockDeleteResponse(t)
107+
fixtures.MockDeleteResponse(t)
107108

108109
res := Delete(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22")
109110
th.AssertNoErr(t, res.Err)
@@ -113,7 +114,7 @@ func TestUpdate(t *testing.T) {
113114
th.SetupHTTP()
114115
defer th.TeardownHTTP()
115116

116-
MockUpdateResponse(t)
117+
fixtures.MockUpdateResponse(t)
117118

118119
options := UpdateOpts{Name: "vol-002"}
119120
v, err := Update(client.ServiceClient(), "d32019d3-bc6e-4319-9c1d-6722fc136a22", options).Extract()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
This is package created is to hold fixtures (which imports testing),
3+
so that importing volumes package does not inadvertently import testing into production code
4+
More information here:
5+
https://github.com/rackspace/gophercloud/issues/473
6+
*/
7+
package testing

openstack/blockstorage/v1/volumes/fixtures.go renamed to openstack/blockstorage/v1/volumes/testing/fixtures.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package volumes
1+
package testing
22

33
import (
44
"fmt"

openstack/compute/v2/extensions/volumeattach/requests_test.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,44 @@ package volumeattach
33
import (
44
"testing"
55

6+
fixtures "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/volumeattach/testing"
67
"github.com/rackspace/gophercloud/pagination"
78
th "github.com/rackspace/gophercloud/testhelper"
89
"github.com/rackspace/gophercloud/testhelper/client"
910
)
1011

12+
// FirstVolumeAttachment is the first result in ListOutput.
13+
var FirstVolumeAttachment = VolumeAttachment{
14+
Device: "/dev/vdd",
15+
ID: "a26887c6-c47b-4654-abb5-dfadf7d3f803",
16+
ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
17+
VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f803",
18+
}
19+
20+
// SecondVolumeAttachment is the first result in ListOutput.
21+
var SecondVolumeAttachment = VolumeAttachment{
22+
Device: "/dev/vdc",
23+
ID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
24+
ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
25+
VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
26+
}
27+
28+
// ExpectedVolumeAttachmentSlide is the slice of results that should be parsed
29+
// from ListOutput, in the expected order.
30+
var ExpectedVolumeAttachmentSlice = []VolumeAttachment{FirstVolumeAttachment, SecondVolumeAttachment}
31+
32+
//CreatedVolumeAttachment is the parsed result from CreatedOutput.
33+
var CreatedVolumeAttachment = VolumeAttachment{
34+
Device: "/dev/vdc",
35+
ID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
36+
ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
37+
VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
38+
}
39+
1140
func TestList(t *testing.T) {
1241
th.SetupHTTP()
1342
defer th.TeardownHTTP()
14-
HandleListSuccessfully(t)
43+
fixtures.HandleListSuccessfully(t)
1544
serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
1645

1746
count := 0
@@ -30,7 +59,7 @@ func TestList(t *testing.T) {
3059
func TestCreate(t *testing.T) {
3160
th.SetupHTTP()
3261
defer th.TeardownHTTP()
33-
HandleCreateSuccessfully(t)
62+
fixtures.HandleCreateSuccessfully(t)
3463
serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
3564

3665
actual, err := Create(client.ServiceClient(), serverId, CreateOpts{
@@ -44,7 +73,7 @@ func TestCreate(t *testing.T) {
4473
func TestGet(t *testing.T) {
4574
th.SetupHTTP()
4675
defer th.TeardownHTTP()
47-
HandleGetSuccessfully(t)
76+
fixtures.HandleGetSuccessfully(t)
4877
aId := "a26887c6-c47b-4654-abb5-dfadf7d3f804"
4978
serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
5079

@@ -56,7 +85,7 @@ func TestGet(t *testing.T) {
5685
func TestDelete(t *testing.T) {
5786
th.SetupHTTP()
5887
defer th.TeardownHTTP()
59-
HandleDeleteSuccessfully(t)
88+
fixtures.HandleDeleteSuccessfully(t)
6089
aId := "a26887c6-c47b-4654-abb5-dfadf7d3f804"
6190
serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
6291

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
This is package created is to hold fixtures (which imports testing),
3+
so that importing volumeattach package does not inadvertently import testing into production code
4+
More information here:
5+
https://github.com/rackspace/gophercloud/issues/473
6+
*/
7+
package testing

openstack/compute/v2/extensions/volumeattach/fixtures.go renamed to openstack/compute/v2/extensions/volumeattach/testing/fixtures.go

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// +build fixtures
22

3-
package volumeattach
3+
package testing
44

55
import (
66
"fmt"
@@ -55,34 +55,6 @@ const CreateOutput = `
5555
}
5656
`
5757

58-
// FirstVolumeAttachment is the first result in ListOutput.
59-
var FirstVolumeAttachment = VolumeAttachment{
60-
Device: "/dev/vdd",
61-
ID: "a26887c6-c47b-4654-abb5-dfadf7d3f803",
62-
ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
63-
VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f803",
64-
}
65-
66-
// SecondVolumeAttachment is the first result in ListOutput.
67-
var SecondVolumeAttachment = VolumeAttachment{
68-
Device: "/dev/vdc",
69-
ID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
70-
ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
71-
VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
72-
}
73-
74-
// ExpectedVolumeAttachmentSlide is the slice of results that should be parsed
75-
// from ListOutput, in the expected order.
76-
var ExpectedVolumeAttachmentSlice = []VolumeAttachment{FirstVolumeAttachment, SecondVolumeAttachment}
77-
78-
// CreatedVolumeAttachment is the parsed result from CreatedOutput.
79-
var CreatedVolumeAttachment = VolumeAttachment{
80-
Device: "/dev/vdc",
81-
ID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
82-
ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
83-
VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
84-
}
85-
8658
// HandleListSuccessfully configures the test server to respond to a List request.
8759
func HandleListSuccessfully(t *testing.T) {
8860
th.Mux.HandleFunc("/servers/4d8c3732-a248-40ed-bebc-539a6ffd25c0/os-volume_attachments", func(w http.ResponseWriter, r *http.Request) {

rackspace/blockstorage/v1/volumes/delegate_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package volumes
33
import (
44
"testing"
55

6-
os "github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes"
6+
"github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes"
7+
os "github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes/testing"
78
"github.com/rackspace/gophercloud/pagination"
89
th "github.com/rackspace/gophercloud/testhelper"
910
fake "github.com/rackspace/gophercloud/testhelper/client"
@@ -64,20 +65,20 @@ func TestCreate(t *testing.T) {
6465

6566
os.MockCreateResponse(t)
6667

67-
n, err := Create(fake.ServiceClient(), CreateOpts{os.CreateOpts{Size: 75}}).Extract()
68+
n, err := Create(fake.ServiceClient(), CreateOpts{volumes.CreateOpts{Size: 75}}).Extract()
6869
th.AssertNoErr(t, err)
6970

7071
th.AssertEquals(t, n.Size, 4)
7172
th.AssertEquals(t, n.ID, "d32019d3-bc6e-4319-9c1d-6722fc136a22")
7273
}
7374

7475
func TestSizeRange(t *testing.T) {
75-
_, err := Create(fake.ServiceClient(), CreateOpts{os.CreateOpts{Size: 1}}).Extract()
76+
_, err := Create(fake.ServiceClient(), CreateOpts{volumes.CreateOpts{Size: 1}}).Extract()
7677
if err == nil {
7778
t.Fatalf("Expected error, got none")
7879
}
7980

80-
_, err = Create(fake.ServiceClient(), CreateOpts{os.CreateOpts{Size: 2000}}).Extract()
81+
_, err = Create(fake.ServiceClient(), CreateOpts{volumes.CreateOpts{Size: 2000}}).Extract()
8182
if err == nil {
8283
t.Fatalf("Expected error, got none")
8384
}

rackspace/compute/v2/volumeattach/delegate_test.go

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,53 @@ package volumeattach
33
import (
44
"testing"
55

6-
os "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/volumeattach"
6+
"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/volumeattach"
7+
fixtures "github.com/rackspace/gophercloud/openstack/compute/v2/extensions/volumeattach/testing"
78
"github.com/rackspace/gophercloud/pagination"
89
th "github.com/rackspace/gophercloud/testhelper"
910
"github.com/rackspace/gophercloud/testhelper/client"
1011
)
1112

13+
// FirstVolumeAttachment is the first result in ListOutput.
14+
var FirstVolumeAttachment = volumeattach.VolumeAttachment{
15+
Device: "/dev/vdd",
16+
ID: "a26887c6-c47b-4654-abb5-dfadf7d3f803",
17+
ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
18+
VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f803",
19+
}
20+
21+
// SecondVolumeAttachment is the first result in ListOutput.
22+
var SecondVolumeAttachment = volumeattach.VolumeAttachment{
23+
Device: "/dev/vdc",
24+
ID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
25+
ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
26+
VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
27+
}
28+
29+
// ExpectedVolumeAttachmentSlide is the slice of results that should be parsed
30+
// from ListOutput, in the expected order.
31+
var ExpectedVolumeAttachmentSlice = []volumeattach.VolumeAttachment{FirstVolumeAttachment, SecondVolumeAttachment}
32+
33+
//CreatedVolumeAttachment is the parsed result from CreatedOutput.
34+
var CreatedVolumeAttachment = volumeattach.VolumeAttachment{
35+
Device: "/dev/vdc",
36+
ID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
37+
ServerID: "4d8c3732-a248-40ed-bebc-539a6ffd25c0",
38+
VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
39+
}
40+
1241
func TestList(t *testing.T) {
1342
th.SetupHTTP()
1443
defer th.TeardownHTTP()
15-
os.HandleListSuccessfully(t)
44+
fixtures.HandleListSuccessfully(t)
1645
serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
1746

1847
count := 0
1948
err := List(client.ServiceClient(), serverId).EachPage(func(page pagination.Page) (bool, error) {
2049
count++
21-
actual, err := os.ExtractVolumeAttachments(page)
50+
actual, err := volumeattach.ExtractVolumeAttachments(page)
2251
th.AssertNoErr(t, err)
23-
th.CheckDeepEquals(t, os.ExpectedVolumeAttachmentSlice, actual)
52+
th.CheckDeepEquals(t, ExpectedVolumeAttachmentSlice, actual)
2453

2554
return true, nil
2655
})
@@ -31,33 +60,33 @@ func TestList(t *testing.T) {
3160
func TestCreate(t *testing.T) {
3261
th.SetupHTTP()
3362
defer th.TeardownHTTP()
34-
os.HandleCreateSuccessfully(t)
63+
fixtures.HandleCreateSuccessfully(t)
3564
serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
3665

37-
actual, err := Create(client.ServiceClient(), serverId, os.CreateOpts{
66+
actual, err := Create(client.ServiceClient(), serverId, volumeattach.CreateOpts{
3867
Device: "/dev/vdc",
3968
VolumeID: "a26887c6-c47b-4654-abb5-dfadf7d3f804",
4069
}).Extract()
4170
th.AssertNoErr(t, err)
42-
th.CheckDeepEquals(t, &os.CreatedVolumeAttachment, actual)
71+
th.CheckDeepEquals(t, &CreatedVolumeAttachment, actual)
4372
}
4473

4574
func TestGet(t *testing.T) {
4675
th.SetupHTTP()
4776
defer th.TeardownHTTP()
48-
os.HandleGetSuccessfully(t)
77+
fixtures.HandleGetSuccessfully(t)
4978
aId := "a26887c6-c47b-4654-abb5-dfadf7d3f804"
5079
serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
5180

5281
actual, err := Get(client.ServiceClient(), serverId, aId).Extract()
5382
th.AssertNoErr(t, err)
54-
th.CheckDeepEquals(t, &os.SecondVolumeAttachment, actual)
83+
th.CheckDeepEquals(t, &SecondVolumeAttachment, actual)
5584
}
5685

5786
func TestDelete(t *testing.T) {
5887
th.SetupHTTP()
5988
defer th.TeardownHTTP()
60-
os.HandleDeleteSuccessfully(t)
89+
fixtures.HandleDeleteSuccessfully(t)
6190
aId := "a26887c6-c47b-4654-abb5-dfadf7d3f804"
6291
serverId := "4d8c3732-a248-40ed-bebc-539a6ffd25c0"
6392

0 commit comments

Comments
 (0)