1
0
镜像自地址 https://github.com/tuna/tunasync.git 已同步 2025-12-06 06:26:46 +00:00

feature(manager): implement manager server, to be tested

这个提交包含在:
walkerning
2016-04-24 22:33:42 +08:00
提交者 bigeagle
父节点 6062aa4b9d
当前提交 bf31e168a2
共有 6 个文件被更改,包括 341 次插入25 次删除

查看文件

@@ -6,12 +6,79 @@ import (
"io/ioutil"
"math/rand"
"net/http"
"strings"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
type mockDBAdapter struct {
workerStore map[string]worker
statusStore map[string]mirrorStatus
}
func (b *mockDBAdapter) ListWorkers() ([]worker, error) {
workers := make([]worker, len(b.workerStore))
idx := 0
for _, w := range b.workerStore {
workers[idx] = w
idx++
}
return workers, nil
}
func (b *mockDBAdapter) GetWorker(workerID string) (worker, error) {
w, ok := b.workerStore[workerID]
if !ok {
return worker{}, fmt.Errorf("inexist workerId")
}
return w, nil
}
func (b *mockDBAdapter) CreateWorker(w worker) (worker, error) {
_, ok := b.workerStore[w.id]
if ok {
return worker{}, fmt.Errorf("duplicate worker name")
}
b.workerStore[w.id] = w
return w, nil
}
func (b *mockDBAdapter) GetMirrorStatus(workerID, mirrorID string) (mirrorStatus, error) {
// TODO: need to check worker exist first
id := workerID + "/" + mirrorID
status, ok := b.statusStore[id]
if !ok {
return mirrorStatus{}, fmt.Errorf("no mirror %s exists in worker %s", mirrorID, workerID)
}
return status, nil
}
func (b *mockDBAdapter) UpdateMirrorStatus(workerID, mirrorID string, status mirrorStatus) (mirrorStatus, error) {
id := workerID + "/" + mirrorID
b.statusStore[id] = status
return status, nil
}
func (b *mockDBAdapter) ListMirrorStatus(workerID string) ([]mirrorStatus, error) {
var mirrorStatusList []mirrorStatus
for k, v := range b.statusStore {
if wID := strings.Split(k, "/")[1]; wID == workerID {
mirrorStatusList = append(mirrorStatusList, v)
}
}
return mirrorStatusList, nil
}
func (b *mockDBAdapter) ListAllMirrorStatus() ([]mirrorStatus, error) {
var mirrorStatusList []mirrorStatus
for _, v := range b.statusStore {
mirrorStatusList = append(mirrorStatusList, v)
}
return mirrorStatusList, nil
}
func TestHTTPServer(t *testing.T) {
Convey("HTTP server should work", t, func() {
s := makeHTTPServer(false)