-
Notifications
You must be signed in to change notification settings - Fork 5
/
client_test.go
50 lines (44 loc) · 1.01 KB
/
client_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package client
import (
"fmt"
"log"
"sync"
"testing"
"github.com/entertainment-venue/sm/pkg/apputil/storage"
"github.com/gin-gonic/gin"
)
func TestNewClient(t *testing.T) {
port := 8888
ginSrv := gin.Default()
_, err := NewClient(
ClientWithRouter(ginSrv),
ClientWithContainerId(fmt.Sprintf("%s:%d", "127.0.0.1", port)),
ClientWithEtcdAddr([]string{"127.0.0.1:2379"}),
ClientWithService("test-service"),
ClientWithImplementation(&testShard{ids: make(map[string]string)}),
ClientWithLogPath("./logs"),
ClientWithLogConsole(false),
)
if err != nil {
log.Fatal(err)
}
_ = ginSrv.Run(fmt.Sprintf(":%d", port))
}
type testShard struct {
lock sync.Mutex
ids map[string]string
}
func (s *testShard) Add(id string, spec *storage.ShardSpec) error {
s.lock.Lock()
defer s.lock.Unlock()
s.ids[id] = ""
fmt.Printf("add op for %s %+v\n", id, *spec)
return nil
}
func (s *testShard) Drop(id string) error {
s.lock.Lock()
defer s.lock.Unlock()
delete(s.ids, id)
fmt.Printf("drop op %s\n", id)
return nil
}