Skip to content

Commit

Permalink
Add integration test (#30)
Browse files Browse the repository at this point in the history
* Update docker-compose to pull from registry

* Add integration test
  • Loading branch information
Puneetha17 authored and conor10 committed Aug 23, 2018
1 parent a71365e commit 9a73e02
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ clean:
$Q rm -rf bin .GOPATH

test: .GOPATH/.ok
$Q ./bin/crux --url=http://127.0.0.1:9020/ --port=9020 --workdir=test/test1 --publickeys=testdata/key.pub --privatekeys=testdata/key &
$Q ./bin/crux --url=http://127.0.0.1:9025/ --port=9025 --workdir=test/test2 --publickeys=testdata/rcpt1.pub --privatekeys=testdata/rcpt1 &
$Q go test $(if $V,-v) -i -race $(allpackages) # install -race libs to speed up next run
ifndef CI
$Q go vet $(allpackages)
Expand All @@ -38,6 +40,7 @@ else
$Q ( GODEBUG=cgocheck=2 go test -v -race $(allpackages); echo $$? ) | \
tee .GOPATH/test/output.txt | sed '$$ d'; exit $$(tail -1 .GOPATH/test/output.txt)
endif
$Q pkill crux

list: .GOPATH/.ok
@echo $(allpackages)
Expand Down
82 changes: 82 additions & 0 deletions test/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package client

import (
"golang.org/x/net/context"
"google.golang.org/grpc"
"github.com/blk-io/chimera-api/chimera"
"encoding/base64"
"reflect"
"testing"
)

const sender = "zSifTnkv5r4K67Dq304eVcM4FpxGfHLe1yTCBm0/7wg="
const receiver = "I/EbshW61ykJ+qTivXPaKyQ5WmQDUFfMNGEBj2E2uUs="
var payload = []byte("payload")


func TestIntegration(t *testing.T) {
var conn1 *grpc.ClientConn
var conn2 *grpc.ClientConn
// Initiate a connection with the first server
conn1, err := grpc.Dial(":9020", grpc.WithInsecure())
if err != nil {
t.Fatalf("did not connect: %s", err)
}
defer conn1.Close()
c1 := chimera.NewClientClient(conn1)
// Initiate a connection with the second server
conn2, err = grpc.Dial(":9025", grpc.WithInsecure())
if err != nil {
t.Fatalf("did not connect: %s", err)
}
defer conn2.Close()
c2 := chimera.NewClientClient(conn2)

Upcheckresponse1, err := c1.Upcheck(context.Background(), &chimera.UpCheckResponse{Message: "foo"})
if err != nil {
t.Fatalf("error when calling Upcheck: %s", err)
}
t.Logf("Response from server: %s", Upcheckresponse1.Message)

Upcheckresponse2, err := c2.Upcheck(context.Background(), &chimera.UpCheckResponse{Message: "foo"})
if err != nil {
t.Fatalf("error when calling Upcheck: %s", err)
}
t.Logf("Response from server: %s", Upcheckresponse2.Message)

sendReqs := []chimera.SendRequest{
{
Payload: []byte("payload"),
From: sender,
To: []string{receiver},
},
{
Payload: []byte("test"),
To: []string{},
},
{
Payload: []byte("blk-io crux"),
},
}

sendResponse := chimera.SendResponse{}
for _, sendReq := range sendReqs {
sendResp, err:= c1.Send(context.Background(), &sendReq)
if err != nil {
t.Fatalf("gRPC send failed with %s", err)
}
sendResponse = chimera.SendResponse{Key:sendResp.Key}
t.Logf("The response for Send request is: %s", base64.StdEncoding.EncodeToString(sendResponse.Key))

recResp, err:= c1.Receive(context.Background(), &chimera.ReceiveRequest{Key:sendResponse.Key, To:receiver})
if err != nil {
t.Fatalf("gRPC receive failed with %s", err)
}
receiveResponse := chimera.ReceiveResponse{Payload:recResp.Payload}
if !reflect.DeepEqual(receiveResponse.Payload, sendReq.Payload) {
t.Fatalf("handler returned unexpected response: %v, expected: %v\n", receiveResponse.Payload, sendReq.Payload)
} else {
t.Logf("The payload return is %v", receiveResponse.Payload)
}
}
}
1 change: 1 addition & 0 deletions test/test1/testdata/key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"data":{"bytes":"W1n0C+NfjcU/cUBXsP5FQ/frU+qpvKQ7Pi/Mu5Hf/Ic="},"type":"unlocked"}
1 change: 1 addition & 0 deletions test/test1/testdata/key.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zSifTnkv5r4K67Dq304eVcM4FpxGfHLe1yTCBm0/7wg=
1 change: 1 addition & 0 deletions test/test2/testdata/rcpt1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"data":{"bytes":"9e0UrkhdfGY0kBYuk3Nv3g4FlYXjTHpXORWO2r1An/A="},"type":"unlocked"}
1 change: 1 addition & 0 deletions test/test2/testdata/rcpt1.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I/EbshW61ykJ+qTivXPaKyQ5WmQDUFfMNGEBj2E2uUs=

0 comments on commit 9a73e02

Please sign in to comment.