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 tests on process nested data feature #1547

Merged
merged 5 commits into from
Dec 4, 2019
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
4 changes: 1 addition & 3 deletions e2e/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ func TestAPI(t *testing.T) {
t.Run("instance", testInstance)
t.Run("event", testEvent)
t.Run("execution", testExecution)
t.Run("orchestrator", testOrchestrator)
t.Run("runner/delete", testDeleteRunner)

// complex tests
t.Run("complex-service", testComplexService)
t.Run("orchestrator", testOrchestrator)
}
160 changes: 73 additions & 87 deletions e2e/definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,88 +6,6 @@ import (
"github.com/mesg-foundation/engine/service"
)

func newTestCreateServiceRequest() *pb.CreateServiceRequest {
return &api.CreateServiceRequest{
Sid: "test-service",
Name: "test-service",
Configuration: service.Service_Configuration{
Env: []string{"FOO=1", "BAR=2", "REQUIRED"},
},
Tasks: []*service.Service_Task{
{
Key: "ping",
Inputs: []*service.Service_Parameter{
{
Key: "msg",
Type: "String",
},
},
Outputs: []*service.Service_Parameter{
{
Key: "pong",
Type: "String",
},
},
},
{
Key: "add",
Inputs: []*service.Service_Parameter{
{
Key: "n",
Type: "Number",
},
{
Key: "m",
Type: "Number",
},
},
Outputs: []*service.Service_Parameter{
{
Key: "res",
Type: "Number",
},
},
},
{
Key: "error",
},
},
Events: []*service.Service_Event{
{
Key: "test_service_ready",
},
{
Key: "ping_ok",
Data: []*service.Service_Parameter{
{
Key: "msg",
Type: "String",
},
},
},
{
Key: "add_ok",
Data: []*service.Service_Parameter{
{
Key: "msg",
Type: "String",
},
},
},
{
Key: "error_ok",
Data: []*service.Service_Parameter{
{
Key: "msg",
Type: "String",
},
},
},
},
Source: "QmZ8r6Basr67m1FYe9mar3B9gB1kDfDZnqZvs3EVj46Np4",
}
}

func newTestComplexCreateServiceRequest() *pb.CreateServiceRequest {
return &api.CreateServiceRequest{
Sid: "test-complex-service",
Expand Down Expand Up @@ -124,10 +42,13 @@ func newTestComplexCreateServiceRequest() *pb.CreateServiceRequest {
}
}

func newTestOrchestratorCreateServiceRequest() *pb.CreateServiceRequest {
func newTestCreateServiceRequest() *pb.CreateServiceRequest {
return &api.CreateServiceRequest{
Sid: "test-service-simple",
Name: "test-service-simple",
Sid: "test-service",
Name: "test-service",
Configuration: service.Service_Configuration{
Env: []string{"FOO=1", "BAR=2", "REQUIRED"},
},
Tasks: []*service.Service_Task{
{
Key: "task1",
Expand Down Expand Up @@ -167,6 +88,47 @@ func newTestOrchestratorCreateServiceRequest() *pb.CreateServiceRequest {
},
},
},
{
Key: "task_complex",
Inputs: []*service.Service_Parameter{
{
Key: "msg",
Type: "Object",
Object: []*service.Service_Parameter{
{
Key: "msg",
Type: "String",
},
{
Key: "array",
Type: "String",
Repeated: true,
},
},
},
},
Outputs: []*service.Service_Parameter{
{
Key: "msg",
Type: "Object",
Object: []*service.Service_Parameter{
{
Key: "msg",
Type: "String",
},
{
Key: "timestamp",
Type: "Number",
},
{
Key: "array",
Type: "String",
Repeated: true,
},
},
},
},
},
},
Events: []*service.Service_Event{
{
Expand All @@ -186,10 +148,34 @@ func newTestOrchestratorCreateServiceRequest() *pb.CreateServiceRequest {
},
},
{
Key: "event_after_task",
Key: "test_event_complex",
Data: []*service.Service_Parameter{
{
Key: "msg",
Type: "Object",
Object: []*service.Service_Parameter{
{
Key: "msg",
Type: "String",
},
{
Key: "timestamp",
Type: "Number",
},
{
Key: "array",
Type: "String",
Repeated: true,
},
},
},
},
},
{
Key: "event_after_task",
Data: []*service.Service_Parameter{
{
Key: "task_key",
Type: "String",
},
{
Expand All @@ -199,6 +185,6 @@ func newTestOrchestratorCreateServiceRequest() *pb.CreateServiceRequest {
},
},
},
Source: "QmaGz2grYKGSYX92ELC3DWoB8KZ6jnWhig5aSfL37AVByF",
Source: "Qmcbi3CFeCRTDVkvkthx81wfDBc8yySKmEgsSEJYwQUqbF",
}
}
106 changes: 88 additions & 18 deletions e2e/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package main
import (
"context"
"testing"
"time"

"github.com/mesg-foundation/engine/hash"
"github.com/mesg-foundation/engine/protobuf/acknowledgement"
pb "github.com/mesg-foundation/engine/protobuf/api"
"github.com/mesg-foundation/engine/protobuf/types"
Expand All @@ -17,26 +19,94 @@ func testEvent(t *testing.T) {
require.NoError(t, err)
acknowledgement.WaitForStreamToBeReady(stream)

resp, err := client.EventClient.Create(context.Background(), &pb.CreateEventRequest{
InstanceHash: testInstanceHash,
Key: "ping_ok",
Data: &types.Struct{
Fields: map[string]*types.Value{
"msg": {
Kind: &types.Value_StringValue{
StringValue: "foo",
t.Run("simple event", func(t *testing.T) {
var (
eventHash hash.Hash
data = &types.Struct{
Fields: map[string]*types.Value{
"msg": {
Kind: &types.Value_StringValue{
StringValue: "foo",
},
},
"timestamp": {
Kind: &types.Value_NumberValue{
NumberValue: float64(time.Now().Unix()),
},
},
},
},
},
}
)
t.Run("create", func(t *testing.T) {
resp, err := client.EventClient.Create(context.Background(), &pb.CreateEventRequest{
InstanceHash: testInstanceHash,
Key: "test_event",
Data: data,
})
require.NoError(t, err)
eventHash = resp.Hash
})
t.Run("receive", func(t *testing.T) {
event, err := stream.Recv()
require.NoError(t, err)
require.Equal(t, eventHash, event.Hash)
require.Equal(t, testInstanceHash, event.InstanceHash)
require.Equal(t, "test_event", event.Key)
require.True(t, data.Equal(event.Data))
})
})
require.NoError(t, err)

event, err := stream.Recv()
require.NoError(t, err)

require.Equal(t, resp.Hash, event.Hash)
require.Equal(t, testInstanceHash, event.InstanceHash)
require.Equal(t, "ping_ok", event.Key)
require.Equal(t, "foo", event.Data.Fields["msg"].GetStringValue())
t.Run("complex event", func(t *testing.T) {
var (
eventHash hash.Hash
data = &types.Struct{
Fields: map[string]*types.Value{
"msg": {
Kind: &types.Value_StructValue{
StructValue: &types.Struct{
Fields: map[string]*types.Value{
"msg": {
Kind: &types.Value_StringValue{
StringValue: "complex",
},
},
"timestamp": {
Kind: &types.Value_NumberValue{
NumberValue: float64(time.Now().Unix()),
},
},
"array": {
Kind: &types.Value_ListValue{
ListValue: &types.ListValue{Values: []*types.Value{
{Kind: &types.Value_StringValue{StringValue: "first"}},
{Kind: &types.Value_StringValue{StringValue: "second"}},
{Kind: &types.Value_StringValue{StringValue: "third"}},
}},
},
},
},
},
},
},
},
}
)
t.Run("create", func(t *testing.T) {
resp, err := client.EventClient.Create(context.Background(), &pb.CreateEventRequest{
InstanceHash: testInstanceHash,
Key: "test_event_complex",
Data: data,
})
require.NoError(t, err)
eventHash = resp.Hash
})
t.Run("receive", func(t *testing.T) {
event, err := stream.Recv()
require.NoError(t, err)
require.Equal(t, eventHash, event.Hash)
require.Equal(t, testInstanceHash, event.InstanceHash)
require.Equal(t, "test_event_complex", event.Key)
require.True(t, data.Equal(event.Data))
})
})
}
Loading