Skip to content

Commit baf8708

Browse files
committed
Clean up the code
1 parent 8de3ce6 commit baf8708

File tree

19 files changed

+197
-337
lines changed

19 files changed

+197
-337
lines changed

client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type Client struct {
4343
*ReplicationMgr
4444
*FileShareMgr
4545
*HostMgr
46-
*ZoneMgr
46+
*AvailabilityZoneMgr
4747

4848
cfg *Config
4949
}
@@ -101,7 +101,7 @@ func NewClient(c *Config) (*Client, error) {
101101
ReplicationMgr: NewReplicationMgr(r, c.Endpoint, t),
102102
FileShareMgr: NewFileShareMgr(r, c.Endpoint, t),
103103
HostMgr: NewHostMgr(r, c.Endpoint, t),
104-
ZoneMgr: NewZoneMgr(r, c.Endpoint, t),
104+
AvailabilityZoneMgr: NewAvailabilityZoneMgr(r, c.Endpoint, t),
105105
}, nil
106106
}
107107

client/fake.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,12 @@ func NewFakeClient(config *Config) *Client {
6363
Receiver: NewFakeFileShareReceiver(),
6464
Endpoint: config.Endpoint,
6565
},
66-
<<<<<<< 211553282aff0b5c8d3f9d7faec703fbb9d34cdb
6766
HostMgr: &HostMgr{
6867
Receiver: NewFakeHostReceiver(),
69-
=======
70-
ZoneMgr: &ZoneMgr{
68+
Endpoint: config.Endpoint,
69+
},
70+
AvailabilityZoneMgr: &AvailabilityZoneMgr{
7171
Receiver: NewFakeZoneReceiver(),
72-
>>>>>>> Add testcases for zone client
7372
Endpoint: config.Endpoint,
7473
},
7574
}
@@ -509,8 +508,8 @@ func (*fakeZoneReceiver) Recv(
509508
switch strings.ToUpper(method) {
510509
case "POST":
511510
switch out.(type) {
512-
case *model.ZoneSpec:
513-
if err := json.Unmarshal([]byte(ByteZone), out); err != nil {
511+
case *model.AvailabilityZoneSpec:
512+
if err := json.Unmarshal([]byte(ByteAvailabilityZone), out); err != nil {
514513
return err
515514
}
516515
break
@@ -520,13 +519,13 @@ func (*fakeZoneReceiver) Recv(
520519
break
521520
case "GET":
522521
switch out.(type) {
523-
case *model.ZoneSpec:
524-
if err := json.Unmarshal([]byte(ByteZone), out); err != nil {
522+
case *model.AvailabilityZoneSpec:
523+
if err := json.Unmarshal([]byte(ByteAvailabilityZone), out); err != nil {
525524
return err
526525
}
527526
break
528-
case *[]*model.ZoneSpec:
529-
if err := json.Unmarshal([]byte(ByteZones), out); err != nil {
527+
case *[]*model.AvailabilityZoneSpec:
528+
if err := json.Unmarshal([]byte(ByteAvailabilityZones), out); err != nil {
530529
return err
531530
}
532531
break
@@ -536,8 +535,8 @@ func (*fakeZoneReceiver) Recv(
536535
break
537536
case "PUT":
538537
switch out.(type) {
539-
case *model.ZoneSpec:
540-
if err := json.Unmarshal([]byte(ByteZone), out); err != nil {
538+
case *model.AvailabilityZoneSpec:
539+
if err := json.Unmarshal([]byte(ByteAvailabilityZone), out); err != nil {
541540
return err
542541
}
543542
break

client/zone.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,30 @@ import (
2121
"github.com/opensds/opensds/pkg/utils/urls"
2222
)
2323

24-
// ZoneBuilder contains request body of handling a zone request.
25-
// Currently it's assigned as the pointer of ZoneSpec struct, but it
24+
// AvailabilityZoneBuilder contains request body of handling a zone request.
25+
// Currently it's assigned as the pointer of AvailabilityZoneSpec struct, but it
2626
// could be discussed if it's better to define an interface.
27-
type ZoneBuilder *model.ZoneSpec
27+
type AvailabilityZoneBuilder *model.AvailabilityZoneSpec
2828

29-
// NewZoneMgr
30-
func NewZoneMgr(r Receiver, edp string, tenantId string) *ZoneMgr {
31-
return &ZoneMgr{
29+
// NewAvailabilityZoneMgr
30+
func NewAvailabilityZoneMgr(r Receiver, edp string, tenantId string) *AvailabilityZoneMgr {
31+
return &AvailabilityZoneMgr{
3232
Receiver: r,
3333
Endpoint: edp,
3434
TenantId: tenantId,
3535
}
3636
}
3737

38-
// ZoneMgr
39-
type ZoneMgr struct {
38+
// AvailabilityZoneMgr
39+
type AvailabilityZoneMgr struct {
4040
Receiver
4141
Endpoint string
4242
TenantId string
4343
}
4444

45-
// CreateZone
46-
func (p *ZoneMgr) CreateZone(body ZoneBuilder) (*model.ZoneSpec, error) {
47-
var res model.ZoneSpec
45+
// CreateAvailabilityZone
46+
func (p *AvailabilityZoneMgr) CreateAvailabilityZone(body AvailabilityZoneBuilder) (*model.AvailabilityZoneSpec, error) {
47+
var res model.AvailabilityZoneSpec
4848
url := strings.Join([]string{
4949
p.Endpoint,
5050
urls.GenerateZoneURL(urls.Client, p.TenantId)}, "/")
@@ -56,9 +56,9 @@ func (p *ZoneMgr) CreateZone(body ZoneBuilder) (*model.ZoneSpec, error) {
5656
return &res, nil
5757
}
5858

59-
// GetZone
60-
func (p *ZoneMgr) GetZone(zoneID string) (*model.ZoneSpec, error) {
61-
var res model.ZoneSpec
59+
// GetAvailabilityZone
60+
func (p *AvailabilityZoneMgr) GetAvailabilityZone(zoneID string) (*model.AvailabilityZoneSpec, error) {
61+
var res model.AvailabilityZoneSpec
6262
url := strings.Join([]string{
6363
p.Endpoint,
6464
urls.GenerateZoneURL(urls.Client, p.TenantId, zoneID)}, "/")
@@ -70,9 +70,9 @@ func (p *ZoneMgr) GetZone(zoneID string) (*model.ZoneSpec, error) {
7070
return &res, nil
7171
}
7272

73-
// UpdateZone ...
74-
func (p *ZoneMgr) UpdateZone(zoneID string, body ZoneBuilder) (*model.ZoneSpec, error) {
75-
var res model.ZoneSpec
73+
// UpdateAvailabilityZone ...
74+
func (p *AvailabilityZoneMgr) UpdateAvailabilityZone(zoneID string, body AvailabilityZoneBuilder) (*model.AvailabilityZoneSpec, error) {
75+
var res model.AvailabilityZoneSpec
7676
url := strings.Join([]string{
7777
p.Endpoint,
7878
urls.GenerateZoneURL(urls.Client, p.TenantId, zoneID)}, "/")
@@ -84,9 +84,9 @@ func (p *ZoneMgr) UpdateZone(zoneID string, body ZoneBuilder) (*model.ZoneSpec,
8484
return &res, nil
8585
}
8686

87-
// ListZones
88-
func (p *ZoneMgr) ListZones(args ...interface{}) ([]*model.ZoneSpec, error) {
89-
var res []*model.ZoneSpec
87+
// ListAvailabilityZones
88+
func (p *AvailabilityZoneMgr) ListAvailabilityZones(args ...interface{}) ([]*model.AvailabilityZoneSpec, error) {
89+
var res []*model.AvailabilityZoneSpec
9090

9191
url := strings.Join([]string{
9292
p.Endpoint,
@@ -107,8 +107,8 @@ func (p *ZoneMgr) ListZones(args ...interface{}) ([]*model.ZoneSpec, error) {
107107
return res, nil
108108
}
109109

110-
// DeleteZone
111-
func (p *ZoneMgr) DeleteZone(zoneID string) error {
110+
// DeleteAvailabilityZone
111+
func (p *AvailabilityZoneMgr) DeleteAvailabilityZone(zoneID string) error {
112112
url := strings.Join([]string{
113113
p.Endpoint,
114114
urls.GenerateZoneURL(urls.Client, p.TenantId, zoneID)}, "/")

client/zone_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ import (
2121
"github.com/opensds/opensds/pkg/model"
2222
)
2323

24-
var fzn = &ZoneMgr{
24+
var fzn = &AvailabilityZoneMgr{
2525
Receiver: NewFakeZoneReceiver(),
2626
}
2727

28-
func TestCreateZone(t *testing.T) {
29-
expected := &model.ZoneSpec{
28+
func TestCreateAvailabilityZone(t *testing.T) {
29+
expected := &model.AvailabilityZoneSpec{
3030
BaseModel: &model.BaseModel{
3131
Id: "1106b972-66ef-11e7-b172-db03f3689c9c",
3232
},
3333
Name: "default",
3434
Description: "default zone",
3535
}
3636

37-
zn, err := fzn.CreateZone(&model.ZoneSpec{})
37+
zn, err := fzn.CreateAvailabilityZone(&model.AvailabilityZoneSpec{})
3838
if err != nil {
3939
t.Error(err)
4040
return
@@ -46,17 +46,17 @@ func TestCreateZone(t *testing.T) {
4646
}
4747
}
4848

49-
func TestGetZone(t *testing.T) {
49+
func TestGetAvailabilityZone(t *testing.T) {
5050
var znID = "1106b972-66ef-11e7-b172-db03f3689c9c"
51-
expected := &model.ZoneSpec{
51+
expected := &model.AvailabilityZoneSpec{
5252
BaseModel: &model.BaseModel{
5353
Id: "1106b972-66ef-11e7-b172-db03f3689c9c",
5454
},
5555
Name: "default",
5656
Description: "default zone",
5757
}
5858

59-
zn, err := fzn.GetZone(znID)
59+
zn, err := fzn.GetAvailabilityZone(znID)
6060
if err != nil {
6161
t.Error(err)
6262
return
@@ -68,8 +68,8 @@ func TestGetZone(t *testing.T) {
6868
}
6969
}
7070

71-
func TestListZones(t *testing.T) {
72-
expected := []*model.ZoneSpec{
71+
func TestListAvailabilityZone(t *testing.T) {
72+
expected := []*model.AvailabilityZoneSpec{
7373
{
7474
BaseModel: &model.BaseModel{
7575
Id: "1106b972-66ef-11e7-b172-db03f3689c9c",
@@ -86,7 +86,7 @@ func TestListZones(t *testing.T) {
8686
},
8787
}
8888

89-
zns, err := fzn.ListZones()
89+
zns, err := fzn.ListAvailabilityZones()
9090
if err != nil {
9191
t.Error(err)
9292
return
@@ -98,16 +98,16 @@ func TestListZones(t *testing.T) {
9898
}
9999
}
100100

101-
func TestUpdateZone(t *testing.T) {
102-
expected := &model.ZoneSpec{
101+
func TestUpdateAvailabilityZone(t *testing.T) {
102+
expected := &model.AvailabilityZoneSpec{
103103
BaseModel: &model.BaseModel{
104104
Id: "1106b972-66ef-11e7-b172-db03f3689c9c",
105105
},
106106
Name: "default",
107107
Description: "default zone",
108108
}
109109

110-
zn, err := fzn.UpdateZone("1106b972-66ef-11e7-b172-db03f3689c9c", &model.ZoneSpec{})
110+
zn, err := fzn.UpdateAvailabilityZone("1106b972-66ef-11e7-b172-db03f3689c9c", &model.AvailabilityZoneSpec{})
111111
if err != nil {
112112
t.Error(err)
113113
return
@@ -119,10 +119,10 @@ func TestUpdateZone(t *testing.T) {
119119
}
120120
}
121121

122-
func TestDeleteZone(t *testing.T) {
122+
func TestDeleteAvailabilityZone(t *testing.T) {
123123
var znID = "1106b972-66ef-11e7-b172-db03f3689c9c"
124124

125-
if err := fzn.DeleteZone(znID); err != nil {
125+
if err := fzn.DeleteAvailabilityZone(znID); err != nil {
126126
t.Error(err)
127127
return
128128
}

osdsctl/cli/zone.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ var zoneFormatters = FormatterList{}
9797

9898
func zoneCreateAction(cmd *cobra.Command, args []string) {
9999
ArgsNumCheck(cmd, args, 1)
100-
az := &model.ZoneSpec{}
100+
az := &model.AvailabilityZoneSpec{}
101101
if err := json.Unmarshal([]byte(args[0]), az); err != nil {
102102
Errorln(err)
103103
cmd.Usage()
104104
os.Exit(1)
105105
}
106106

107-
resp, err := client.CreateZone(az)
107+
resp, err := client.CreateAvailabilityZone(az)
108108
if err != nil {
109109
Fatalln(HttpErrStrip(err))
110110
}
@@ -114,7 +114,7 @@ func zoneCreateAction(cmd *cobra.Command, args []string) {
114114

115115
func zoneShowAction(cmd *cobra.Command, args []string) {
116116
ArgsNumCheck(cmd, args, 1)
117-
resp, err := client.GetZone(args[0])
117+
resp, err := client.GetAvailabilityZone(args[0])
118118
if err != nil {
119119
Fatalln(HttpErrStrip(err))
120120
}
@@ -128,7 +128,7 @@ func zoneListAction(cmd *cobra.Command, args []string) {
128128
"sortKey": zoneSortKey, "Id": zoneId,
129129
"Name": zoneName, "Description": zoneDescription}
130130

131-
resp, err := client.ListZones(opts)
131+
resp, err := client.ListAvailabilityZones(opts)
132132
if err != nil {
133133
Fatalln(HttpErrStrip(err))
134134
}
@@ -138,23 +138,23 @@ func zoneListAction(cmd *cobra.Command, args []string) {
138138

139139
func zoneDeleteAction(cmd *cobra.Command, args []string) {
140140
ArgsNumCheck(cmd, args, 1)
141-
err := client.DeleteZone(args[0])
141+
err := client.DeleteAvailabilityZone(args[0])
142142
if err != nil {
143143
Fatalln(HttpErrStrip(err))
144144
}
145145
}
146146

147147
func zoneUpdateAction(cmd *cobra.Command, args []string) {
148148
ArgsNumCheck(cmd, args, 2)
149-
az := &model.ZoneSpec{}
149+
az := &model.AvailabilityZoneSpec{}
150150

151151
if err := json.Unmarshal([]byte(args[1]), az); err != nil {
152152
Errorln(err)
153153
cmd.Usage()
154154
os.Exit(1)
155155
}
156156

157-
resp, err := client.UpdateZone(args[0], az)
157+
resp, err := client.UpdateAvailabilityZone(args[0], az)
158158
if err != nil {
159159
Fatalln(HttpErrStrip(err))
160160
}

osdsctl/cli/zone_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestZoneAction(t *testing.T) {
5151

5252
func TestZoneCreateAction(t *testing.T) {
5353
var args []string
54-
args = append(args, ByteZone)
54+
args = append(args, ByteAvailabilityZone)
5555
zoneCreateAction(zoneCreateCommand, args)
5656
}
5757

pkg/api/controllers/pool_test.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,9 @@ import (
3232
func init() {
3333
var poolPortal PoolPortal
3434
beego.Router("/v1beta/pools", &poolPortal, "get:ListPools")
35-
// beego.Router("/v1beta/availabilityZones", &poolPortal, "get:ListAvailabilityZones")
3635
beego.Router("/v1beta/pools/:poolId", &poolPortal, "get:GetPool")
3736
}
3837

39-
// func TestListAvailabilityZones(t *testing.T) {
40-
41-
// t.Run("Should return 200 if everything works well", func(t *testing.T) {
42-
// mockClient := new(dbtest.Client)
43-
// mockClient.On("ListAvailabilityZones", c.NewAdminContext()).Return(SampleAvailabilityZones, nil)
44-
// db.C = mockClient
45-
46-
// r, _ := http.NewRequest("GET", "/v1beta/availabilityZones", nil)
47-
// w := httptest.NewRecorder()
48-
// beego.BeeApp.Handlers.ServeHTTP(w, r)
49-
// var output []string
50-
// json.Unmarshal(w.Body.Bytes(), &output)
51-
// assertTestResult(t, w.Code, 200)
52-
// assertTestResult(t, output, SampleAvailabilityZones)
53-
// })
54-
// }
55-
5638
func TestListPools(t *testing.T) {
5739

5840
t.Run("Should return 200 if everything works well", func(t *testing.T) {

0 commit comments

Comments
 (0)