Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add e2e lcd tests for ownerships #1654

Merged
merged 3 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion e2e/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package main

import (
"context"
"io/ioutil"
"net/http"
"testing"

"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/mesg-foundation/engine/app"
pb "github.com/mesg-foundation/engine/protobuf/api"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
Expand All @@ -19,7 +23,23 @@ type apiclient struct {
pb.RunnerClient
}

var client apiclient
var (
client apiclient
cdc = app.MakeCodec()
)

const lcdEndpoint = "http://127.0.0.1:1317/"

func lcdGet(t *testing.T, path string, ptr interface{}) {
resp, err := http.Get(lcdEndpoint + path)
require.NoError(t, err)
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
require.NoError(t, err)
cosResp := rest.ResponseWithHeight{}
require.NoError(t, cdc.UnmarshalJSON(body, &cosResp))
require.NoError(t, cdc.UnmarshalJSON(cosResp.Result, ptr))
}

func TestAPI(t *testing.T) {
if testing.Short() {
Expand Down
42 changes: 31 additions & 11 deletions e2e/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,28 @@ func testProcess(t *testing.T) {
})

t.Run("check ownership creation", func(t *testing.T) {
ownerships, err := client.OwnershipClient.List(context.Background(), &pb.ListOwnershipRequest{})
require.NoError(t, err)
owners := make([]*ownership.Ownership, 0)
for _, o := range ownerships.Ownerships {
if o.ResourceHash.Equal(processHash) && o.Resource == ownership.Ownership_Process && o.Owner != "" {
owners = append(owners, o)
t.Run("lcd", func(t *testing.T) {
ownerships := make([]*ownership.Ownership, 0)
lcdGet(t, "ownership/list", &ownerships)
owners := make([]*ownership.Ownership, 0)
for _, o := range ownerships {
if o.ResourceHash.Equal(processHash) && o.Resource == ownership.Ownership_Process && o.Owner != "" {
owners = append(owners, o)
}
}
}
require.Len(t, owners, 1)
require.Len(t, owners, 1)
})
t.Run("grpc", func(t *testing.T) {
ownerships, err := client.OwnershipClient.List(context.Background(), &pb.ListOwnershipRequest{})
require.NoError(t, err)
owners := make([]*ownership.Ownership, 0)
for _, o := range ownerships.Ownerships {
if o.ResourceHash.Equal(processHash) && o.Resource == ownership.Ownership_Process && o.Owner != "" {
owners = append(owners, o)
}
}
require.Len(t, owners, 1)
})
})

t.Run("list", func(t *testing.T) {
Expand All @@ -89,8 +102,15 @@ func testProcess(t *testing.T) {
})

t.Run("check ownership deletion", func(t *testing.T) {
ownerships, err := client.OwnershipClient.List(context.Background(), &pb.ListOwnershipRequest{})
require.NoError(t, err)
require.Len(t, ownerships.Ownerships, 1)
t.Run("lcd", func(t *testing.T) {
ownerships := make([]*ownership.Ownership, 0)
lcdGet(t, "ownership/list", &ownerships)
require.Len(t, ownerships, 1)
})
t.Run("grpc", func(t *testing.T) {
ownerships, err := client.OwnershipClient.List(context.Background(), &pb.ListOwnershipRequest{})
require.NoError(t, err)
require.Len(t, ownerships.Ownerships, 1)
})
})
}
22 changes: 16 additions & 6 deletions e2e/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,21 @@ func testService(t *testing.T) {
})

t.Run("check ownership creation", func(t *testing.T) {
ownerships, err := client.OwnershipClient.List(context.Background(), &pb.ListOwnershipRequest{})
require.NoError(t, err)
require.Len(t, ownerships.Ownerships, 1)
require.NotEmpty(t, ownerships.Ownerships[0].Owner)
require.Equal(t, ownership.Ownership_Service, ownerships.Ownerships[0].Resource)
require.Equal(t, testServiceHash, ownerships.Ownerships[0].ResourceHash)
t.Run("lcd", func(t *testing.T) {
ownerships, err := client.OwnershipClient.List(context.Background(), &pb.ListOwnershipRequest{})
require.NoError(t, err)
require.Len(t, ownerships.Ownerships, 1)
require.NotEmpty(t, ownerships.Ownerships[0].Owner)
require.Equal(t, ownership.Ownership_Service, ownerships.Ownerships[0].Resource)
require.Equal(t, testServiceHash, ownerships.Ownerships[0].ResourceHash)
})
t.Run("grpc", func(t *testing.T) {
ownerships := make([]*ownership.Ownership, 0)
lcdGet(t, "ownership/list", &ownerships)
require.Len(t, ownerships, 1)
require.NotEmpty(t, ownerships[0].Owner)
require.Equal(t, ownership.Ownership_Service, ownerships[0].Resource)
require.Equal(t, testServiceHash, ownerships[0].ResourceHash)
})
})
}