Browse Source

修复调试发现的Bug

gitlink
Sydonian 2 years ago
parent
commit
2ca778276f
4 changed files with 92 additions and 27 deletions
  1. +1
    -1
      internal/cmdline/bucket.go
  2. +36
    -25
      internal/cmdline/commandline.go
  3. +1
    -1
      internal/cmdline/object.go
  4. +54
    -0
      internal/services/object_test.go

+ 1
- 1
internal/cmdline/bucket.go View File

@@ -7,7 +7,7 @@ import (
"gitlink.org.cn/cloudream/client/internal/services"
)

func (c *Commandline) GetUserBuckets() error {
func (c *Commandline) ListUserBuckets() error {
userID := 0

buckets, err := services.BucketSvc(c.svc).GetUserBuckets(userID)


+ 36
- 25
internal/cmdline/commandline.go View File

@@ -60,41 +60,32 @@ func (c *Commandline) DispatchCommand(cmd string, args []string) {
os.Exit(1)
}

case "move":
objectID, err := strconv.Atoi(args[0])
if err != nil {
fmt.Printf("invalid object id %s, err: %s", args[0], err.Error())
os.Exit(1)
}
stgID, err := strconv.Atoi(args[1])
if err != nil {
fmt.Printf("invalid storage id %s, err: %s", args[1], err.Error())
os.Exit(1)
}

if err := c.Move(objectID, stgID); err != nil {
fmt.Printf("move failed, err: %s", err.Error())
case "storage":
if len(args) == 0 {
fmt.Printf("need more arg")
os.Exit(1)
}
cmd := args[0]

case "ls":
if len(args) == 0 {
if err := c.GetUserBuckets(); err != nil {
fmt.Printf("get user buckets failed, err: %s", err.Error())
switch cmd {
case "move":
objectID, err := strconv.Atoi(args[1])
if err != nil {
fmt.Printf("invalid object id %s, err: %s", args[1], err.Error())
os.Exit(1)
}
} else {
bucketID, err := strconv.Atoi(args[0])
stgID, err := strconv.Atoi(args[2])
if err != nil {
fmt.Printf("invalid bucket id %s, err: %s", args[1], err.Error())
fmt.Printf("invalid storage id %s, err: %s", args[2], err.Error())
os.Exit(1)
}

if err := c.GetBucketObjects(bucketID); err != nil {
fmt.Printf("get bucket objects failed, err: %s", err.Error())
if err := c.Move(objectID, stgID); err != nil {
fmt.Printf("move failed, err: %s", err.Error())
os.Exit(1)
}
}

case "bucket":
if len(args) == 0 {
fmt.Printf("need more arg")
@@ -102,12 +93,20 @@ func (c *Commandline) DispatchCommand(cmd string, args []string) {
}
cmd := args[0]

if cmd == "new" {
switch cmd {
case "ls":
if err := c.ListUserBuckets(); err != nil {
fmt.Printf("get user buckets failed, err: %s", err.Error())
os.Exit(1)
}

case "new":
if err := c.CreateBucket(args[1]); err != nil {
fmt.Printf("create bucket failed, err: %s", err.Error())
os.Exit(1)
}
} else if cmd == "delete" {

case "delete":
bucketID, err := strconv.Atoi(args[1])
if err != nil {
fmt.Printf("invalid bucket id %s, err: %s", args[1], err.Error())
@@ -127,6 +126,18 @@ func (c *Commandline) DispatchCommand(cmd string, args []string) {
}

switch args[0] {
case "ls":
bucketID, err := strconv.Atoi(args[1])
if err != nil {
fmt.Printf("invalid bucket id %s, err: %s", args[1], err.Error())
os.Exit(1)
}

if err := c.ListBucketObjects(bucketID); err != nil {
fmt.Printf("get bucket objects failed, err: %s", err.Error())
os.Exit(1)
}

case "update":
objectID, err := strconv.Atoi(args[1])
if err != nil {


+ 1
- 1
internal/cmdline/object.go View File

@@ -10,7 +10,7 @@ import (
"gitlink.org.cn/cloudream/client/internal/services"
)

func (c *Commandline) GetBucketObjects(bucketID int) error {
func (c *Commandline) ListBucketObjects(bucketID int) error {
userID := 0

objects, err := services.BucketSvc(c.svc).GetBucketObjects(userID, bucketID)


+ 54
- 0
internal/services/object_test.go View File

@@ -0,0 +1,54 @@
package services

import (
"testing"

. "github.com/smartystreets/goconvey/convey"
coormsg "gitlink.org.cn/cloudream/rabbitmq/message/coordinator"
)

func Test_chooseUpdateRepObjectNode(t *testing.T) {
testcases := []struct {
title string
nodes []coormsg.PreUpdateRepObjectRespNode
wantNodeID int
}{
{
title: "选择同地域,包含旧数据的节点",
nodes: []coormsg.PreUpdateRepObjectRespNode{
coormsg.NewPreUpdateRepObjectRespNode(0, "", "", true, false),
coormsg.NewPreUpdateRepObjectRespNode(1, "", "", false, false),
coormsg.NewPreUpdateRepObjectRespNode(2, "", "", false, true),
coormsg.NewPreUpdateRepObjectRespNode(3, "", "", true, true),
},
wantNodeID: 3,
},

{
title: "选择包含旧数据的节点",
nodes: []coormsg.PreUpdateRepObjectRespNode{
coormsg.NewPreUpdateRepObjectRespNode(0, "", "", true, false),
coormsg.NewPreUpdateRepObjectRespNode(1, "", "", false, false),
coormsg.NewPreUpdateRepObjectRespNode(2, "", "", false, true),
},
wantNodeID: 2,
},

{
title: "选择包含同地域的节点",
nodes: []coormsg.PreUpdateRepObjectRespNode{
coormsg.NewPreUpdateRepObjectRespNode(0, "", "", true, false),
coormsg.NewPreUpdateRepObjectRespNode(1, "", "", false, false),
},
wantNodeID: 0,
},
}

var svc ObjectService
for _, test := range testcases {
Convey(test.title, t, func() {
chooseNode := svc.chooseUpdateRepObjectNode(test.nodes)
So(chooseNode.ID, ShouldEqual, test.wantNodeID)
})
}
}

Loading…
Cancel
Save