update
This commit is contained in:
@@ -18,6 +18,9 @@ type CartIdPayload struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func MakeCartInnerFrame(id CartId, payload []byte) []byte {
|
func MakeCartInnerFrame(id CartId, payload []byte) []byte {
|
||||||
|
if payload == nil {
|
||||||
|
return id[:]
|
||||||
|
}
|
||||||
return append(id[:], payload...)
|
return append(id[:], payload...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
17
remote-grain_test.go
Normal file
17
remote-grain_test.go
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestCartIdsNullData(t *testing.T) {
|
||||||
|
data := MakeCartInnerFrame(ToCartId("kalle"), nil)
|
||||||
|
cart, err := GetCartFrame(data)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error getting cart: %v", err)
|
||||||
|
}
|
||||||
|
if cart.Id.String() != "kalle" {
|
||||||
|
t.Errorf("Expected kalle, got %s", cart.Id)
|
||||||
|
}
|
||||||
|
if len(cart.Data) != 0 {
|
||||||
|
t.Errorf("Expected no data, got %v", cart.Data)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -366,12 +366,16 @@ func (p *SyncedPool) AddRemote(host string) {
|
|||||||
if host == "" || hasHost {
|
if host == "" || hasHost {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// if host == "" || hasHost || host == p.Hostname {
|
||||||
|
// return
|
||||||
|
// }
|
||||||
client := NewConnection(fmt.Sprintf("%s:1338", host))
|
client := NewConnection(fmt.Sprintf("%s:1338", host))
|
||||||
_, err := client.Call(Ping, nil)
|
r, err := client.Call(Ping, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error connecting to remote %s: %s\n", host, err)
|
log.Printf("Error connecting to remote %s: %s\n", host, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
log.Printf("Connected to remote %s: %v\n", host, r)
|
||||||
|
|
||||||
remote := RemoteHost{
|
remote := RemoteHost{
|
||||||
Connection: client,
|
Connection: client,
|
||||||
|
|||||||
@@ -13,18 +13,25 @@ func TestConnection(t *testing.T) {
|
|||||||
Id: id,
|
Id: id,
|
||||||
storageMessages: []Message{},
|
storageMessages: []Message{},
|
||||||
Items: []*CartItem{},
|
Items: []*CartItem{},
|
||||||
|
Deliveries: make([]CartDelivery, 0),
|
||||||
TotalPrice: 0,
|
TotalPrice: 0,
|
||||||
}, nil
|
}, nil
|
||||||
})
|
})
|
||||||
|
hg, err := NewGrainHandler(localPool, ":1337")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error creating handler: %v\n", err)
|
||||||
|
}
|
||||||
|
if hg == nil {
|
||||||
|
t.Errorf("Expected handler, got nil")
|
||||||
|
}
|
||||||
pool, err := NewSyncedPool(localPool, "127.0.0.1", nil)
|
pool, err := NewSyncedPool(localPool, "127.0.0.1", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error creating pool: %v", err)
|
t.Errorf("Error creating pool: %v", err)
|
||||||
}
|
}
|
||||||
|
time.Sleep(400 * time.Millisecond)
|
||||||
|
pool.AddRemote("127.0.0.1")
|
||||||
|
|
||||||
err = pool.AddRemote("127.0.0.1")
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Error adding remote: %v", err)
|
|
||||||
}
|
|
||||||
go pool.Negotiate()
|
go pool.Negotiate()
|
||||||
|
|
||||||
data, err := pool.Get(ToCartId("kalle"))
|
data, err := pool.Get(ToCartId("kalle"))
|
||||||
|
|||||||
Reference in New Issue
Block a user