update stuff
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m52s
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m52s
This commit is contained in:
@@ -43,10 +43,10 @@ type CartGrain struct {
|
|||||||
lastItemId int
|
lastItemId int
|
||||||
lastDeliveryId int
|
lastDeliveryId int
|
||||||
storageMessages []Message
|
storageMessages []Message
|
||||||
Id CartId `json:"id"`
|
Id CartId `json:"id"`
|
||||||
Items []CartItem `json:"items"`
|
Items []*CartItem `json:"items"`
|
||||||
TotalPrice int64 `json:"totalPrice"`
|
TotalPrice int64 `json:"totalPrice"`
|
||||||
Deliveries []string `json:"deliveries,omitempty"`
|
Deliveries []string `json:"deliveries,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Grain interface {
|
type Grain interface {
|
||||||
@@ -152,16 +152,17 @@ func (c *CartGrain) HandleMessage(message *Message, isReplay bool) ([]byte, erro
|
|||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
c.lastItemId++
|
c.lastItemId++
|
||||||
c.Items = append(c.Items, CartItem{
|
c.Items = append(c.Items, &CartItem{
|
||||||
Id: c.lastItemId,
|
Id: c.lastItemId,
|
||||||
|
Quantity: int(msg.Quantity),
|
||||||
Sku: msg.Sku,
|
Sku: msg.Sku,
|
||||||
Name: msg.Name,
|
Name: msg.Name,
|
||||||
Price: msg.Price,
|
Price: msg.Price,
|
||||||
Image: msg.Image,
|
Image: msg.Image,
|
||||||
})
|
})
|
||||||
|
c.TotalPrice += msg.Price * int64(msg.Quantity)
|
||||||
}
|
}
|
||||||
c.TotalPrice += msg.Price * int64(msg.Quantity)
|
|
||||||
}
|
}
|
||||||
case RemoveItemType:
|
case RemoveItemType:
|
||||||
//msg, ok := message.Content.(*messages.RemoveItem)
|
//msg, ok := message.Content.(*messages.RemoveItem)
|
||||||
|
|||||||
@@ -39,5 +39,23 @@ func TestAddToCart(t *testing.T) {
|
|||||||
if grain.TotalPrice != 200 {
|
if grain.TotalPrice != 200 {
|
||||||
t.Errorf("Expected total price 200, got %d\n", grain.TotalPrice)
|
t.Errorf("Expected total price 200, got %d\n", grain.TotalPrice)
|
||||||
}
|
}
|
||||||
|
if len(grain.Items) != 1 {
|
||||||
|
t.Errorf("Expected 1 item, got %d\n", len(grain.Items))
|
||||||
|
}
|
||||||
|
if grain.Items[0].Quantity != 2 {
|
||||||
|
t.Errorf("Expected quantity 2, got %d\n", grain.Items[0].Quantity)
|
||||||
|
}
|
||||||
|
result, err = grain.HandleMessage(msg, false)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error handling message: %v\n", err)
|
||||||
|
}
|
||||||
|
if len(result) == 0 {
|
||||||
|
t.Errorf("Expected result, got nil\n")
|
||||||
|
}
|
||||||
|
if grain.Items[0].Quantity != 4 {
|
||||||
|
t.Errorf("Expected quantity 4, got %d\n", grain.Items[0].Quantity)
|
||||||
|
}
|
||||||
|
if grain.TotalPrice != 400 {
|
||||||
|
t.Errorf("Expected total price 400, got %d\n", grain.TotalPrice)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -40,7 +40,7 @@ func spawn(id CartId) (*CartGrain, error) {
|
|||||||
lastDeliveryId: 0,
|
lastDeliveryId: 0,
|
||||||
Deliveries: []string{},
|
Deliveries: []string{},
|
||||||
Id: id,
|
Id: id,
|
||||||
Items: []CartItem{},
|
Items: []*CartItem{},
|
||||||
storageMessages: []Message{},
|
storageMessages: []Message{},
|
||||||
TotalPrice: 0,
|
TotalPrice: 0,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ func TestQueue(t *testing.T) {
|
|||||||
return &CartGrain{
|
return &CartGrain{
|
||||||
Id: id,
|
Id: id,
|
||||||
storageMessages: []Message{},
|
storageMessages: []Message{},
|
||||||
Items: []CartItem{},
|
Items: []*CartItem{},
|
||||||
TotalPrice: 0,
|
TotalPrice: 0,
|
||||||
}, nil
|
}, nil
|
||||||
})
|
})
|
||||||
@@ -22,11 +22,7 @@ func TestQueue(t *testing.T) {
|
|||||||
err = pool.AddRemote("localhost")
|
err = pool.AddRemote("localhost")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error adding remote: %v", err)
|
t.Errorf("Error adding remote: %v", err)
|
||||||
}
|
return
|
||||||
r := pool.remotes[0]
|
|
||||||
|
|
||||||
if len(r.PacketQueue.Packets) != 1 {
|
|
||||||
t.Errorf("Expected 1 packet, got %d", len(r.PacketQueue.Packets))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -387,7 +387,6 @@ func (p *SyncedPool) AddRemote(host string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//pool := NewRemoteGrainPool(host)
|
|
||||||
remote := RemoteHost{
|
remote := RemoteHost{
|
||||||
Client: client,
|
Client: client,
|
||||||
MissedPings: 0,
|
MissedPings: 0,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ func TestConnection(t *testing.T) {
|
|||||||
return &CartGrain{
|
return &CartGrain{
|
||||||
Id: id,
|
Id: id,
|
||||||
storageMessages: []Message{},
|
storageMessages: []Message{},
|
||||||
Items: []CartItem{},
|
Items: []*CartItem{},
|
||||||
TotalPrice: 0,
|
TotalPrice: 0,
|
||||||
}, nil
|
}, nil
|
||||||
})
|
})
|
||||||
@@ -29,8 +29,8 @@ func TestConnection(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error negotiating: %v", err)
|
t.Errorf("Error negotiating: %v", err)
|
||||||
}
|
}
|
||||||
if len(allHosts) != 1 {
|
if len(allHosts) != 0 {
|
||||||
t.Errorf("Expected 1 host, got %d", len(allHosts))
|
t.Errorf("Expected 0 host, (host should be known) got %d", len(allHosts))
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := pool.Get(ToCartId("kalle"))
|
data, err := pool.Get(ToCartId("kalle"))
|
||||||
|
|||||||
Reference in New Issue
Block a user