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 of a complex service #1500

Merged
merged 17 commits into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from 14 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
10 changes: 4 additions & 6 deletions e2e/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ import (
pb "github.com/mesg-foundation/engine/protobuf/api"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
)

var passmd = metadata.Pairs(
"credential_username", "engine",
"credential_passphrase", "pass",
)

type apiclient struct {
Expand Down Expand Up @@ -51,6 +45,7 @@ func TestAPI(t *testing.T) {
_, err = client.ServiceClient.List(context.Background(), &pb.ListServiceRequest{})
require.NoError(t, err)

// basic tests
t.Run("account", testAccount)
t.Run("service", testService)
t.Run("ownership", testOwnership)
Expand All @@ -59,4 +54,7 @@ func TestAPI(t *testing.T) {
t.Run("event", testEvent)
t.Run("execution", testExecution)
t.Run("runner/delete", testDeleteRunner)

// complex tests
t.Run("complex-service", testComplexService)
}
70 changes: 70 additions & 0 deletions e2e/complex_service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package main

import (
"context"
"testing"

"github.com/mesg-foundation/engine/hash"
"github.com/mesg-foundation/engine/protobuf/acknowledgement"
pb "github.com/mesg-foundation/engine/protobuf/api"
"github.com/stretchr/testify/require"
)

func testComplexService(t *testing.T) {
var (
testServiceHash hash.Hash
testRunnerHashC hash.Hash
testInstanceHash hash.Hash
)

req := newTestComplexCreateServiceRequest()

t.Run("create", func(t *testing.T) {
resp, err := client.ServiceClient.Create(context.Background(), req)
require.NoError(t, err)
testServiceHash = resp.Hash
})

stream, err := client.EventClient.Stream(context.Background(), &pb.StreamEventRequest{})
require.NoError(t, err)
acknowledgement.WaitForStreamToBeReady(stream)

t.Run("run", func(t *testing.T) {
resp, err := client.RunnerClient.Create(context.Background(), &pb.CreateRunnerRequest{
ServiceHash: testServiceHash,
Env: []string{"ENVB=is_override"},
})
require.NoError(t, err)
testRunnerHashC = resp.Hash

resp1, err := client.RunnerClient.Get(context.Background(), &pb.GetRunnerRequest{Hash: testRunnerHashC})
require.NoError(t, err)
testInstanceHash = resp1.InstanceHash
})

t.Run("check events", func(t *testing.T) {
okEventsNo := 6
for i := 0; i < okEventsNo; {
ev, err := stream.Recv()
require.NoError(t, err)

if !ev.InstanceHash.Equal(testInstanceHash) {
continue
}
i++

switch ev.Key {
case "test_service_ready", "read_env_ok", "read_env_override_ok", "access_volumes_ok", "access_volumes_from_ok", "resolve_dependence_ok":
t.Logf("received event %s ", ev.Key)
default:
t.Fatalf("failed on event %s", ev.Key)
}
}
})

t.Run("delete", func(t *testing.T) {
t.Skip("FIXME: this call never get trough. some issue with the service's dependency")
_, err := client.RunnerClient.Delete(context.Background(), &pb.DeleteRunnerRequest{Hash: testRunnerHashC})
require.NoError(t, err)
})
}
125 changes: 125 additions & 0 deletions e2e/definition_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package main

import (
"github.com/mesg-foundation/engine/protobuf/api"
pb "github.com/mesg-foundation/engine/protobuf/api"
"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: "QmPG1Ze96pH1EgVMWsGKM33jXoG63rigMncSEqZXP7oncq",
krhubert marked this conversation as resolved.
Show resolved Hide resolved
}
}

func newTestComplexCreateServiceRequest() *pb.CreateServiceRequest {
return &api.CreateServiceRequest{
Sid: "test-complex-service",
Name: "test-complex-service",
Dependencies: []*service.Service_Dependency{
{
Key: "nginx",
Image: "nginx",
Volumes: []string{"/etc/nginx"},
},
},
Configuration: service.Service_Configuration{
Env: []string{
"ENVA=do_not_override",
"ENVB=override",
},
Volumes: []string{"/volume/test/"},
VolumesFrom: []string{"nginx"},
},
Events: []*service.Service_Event{
{Key: "test_service_ready"},
{Key: "read_env_ok"},
{Key: "read_env_error"},
{Key: "read_env_override_ok"},
{Key: "read_env_override_error"},
{Key: "access_volumes_ok"},
{Key: "access_volumes_error"},
{Key: "access_volumes_from_ok"},
{Key: "access_volumes_from_error"},
{Key: "resolve_dependence_ok"},
{Key: "resolve_dependence_error"},
},
Source: "QmXrYtcrs5UZjAZXsfGuBNjyawvdPV7pA44XdodP9gPjtt",
}
}
6 changes: 2 additions & 4 deletions e2e/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
pb "github.com/mesg-foundation/engine/protobuf/api"
"github.com/mesg-foundation/engine/protobuf/types"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/metadata"
)

func testExecution(t *testing.T) {
Expand All @@ -21,8 +20,7 @@ func testExecution(t *testing.T) {
require.NoError(t, err)
acknowledgement.WaitForStreamToBeReady(stream)

ctx := metadata.NewOutgoingContext(context.Background(), passmd)
resp, err := client.ExecutionClient.Create(ctx, &pb.CreateExecutionRequest{
resp, err := client.ExecutionClient.Create(context.Background(), &pb.CreateExecutionRequest{
InstanceHash: testInstanceHash,
TaskKey: "ping",
Inputs: &types.Struct{
Expand Down Expand Up @@ -51,7 +49,7 @@ func testExecution(t *testing.T) {
require.Equal(t, "ping", exec.TaskKey)
require.Equal(t, execution.Status_Completed, exec.Status)

exec, err = client.ExecutionClient.Get(ctx, &pb.GetExecutionRequest{Hash: resp.Hash})
exec, err = client.ExecutionClient.Get(context.Background(), &pb.GetExecutionRequest{Hash: resp.Hash})
require.NoError(t, err)
require.Equal(t, resp.Hash, exec.Hash)
require.Equal(t, "ping", exec.TaskKey)
Expand Down
4 changes: 1 addition & 3 deletions e2e/ownership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import (
"github.com/mesg-foundation/engine/ownership"
pb "github.com/mesg-foundation/engine/protobuf/api"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/metadata"
)

func testOwnership(t *testing.T) {
t.Run("list", func(t *testing.T) {
ctx := metadata.NewOutgoingContext(context.Background(), passmd)
ownerships, err := client.OwnershipClient.List(ctx, &pb.ListOwnershipRequest{})
ownerships, err := client.OwnershipClient.List(context.Background(), &pb.ListOwnershipRequest{})
require.NoError(t, err)

acc, err := client.AccountClient.Get(context.Background(), &pb.GetAccountRequest{Name: "engine"})
Expand Down
7 changes: 2 additions & 5 deletions e2e/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/mesg-foundation/engine/protobuf/acknowledgement"
pb "github.com/mesg-foundation/engine/protobuf/api"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/metadata"
)

var testRunnerHash hash.Hash
Expand All @@ -23,8 +22,7 @@ func testRunner(t *testing.T) {
require.NoError(t, err)
acknowledgement.WaitForStreamToBeReady(stream)

ctx := metadata.NewOutgoingContext(context.Background(), passmd)
resp, err := client.RunnerClient.Create(ctx, &pb.CreateRunnerRequest{
resp, err := client.RunnerClient.Create(context.Background(), &pb.CreateRunnerRequest{
ServiceHash: testServiceHash,
Env: []string{"BAR=3", "REQUIRED=4"},
})
Expand Down Expand Up @@ -53,8 +51,7 @@ func testRunner(t *testing.T) {
}

func testDeleteRunner(t *testing.T) {
ctx := metadata.NewOutgoingContext(context.Background(), passmd)
_, err := client.RunnerClient.Delete(ctx, &pb.DeleteRunnerRequest{Hash: testRunnerHash})
_, err := client.RunnerClient.Delete(context.Background(), &pb.DeleteRunnerRequest{Hash: testRunnerHash})
require.NoError(t, err)

resp, err := client.RunnerClient.List(context.Background(), &pb.ListRunnerRequest{})
Expand Down
32 changes: 4 additions & 28 deletions e2e/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,26 @@ package main

import (
"context"
"encoding/json"
"io/ioutil"
"log"
"testing"

"github.com/mesg-foundation/engine/hash"
pb "github.com/mesg-foundation/engine/protobuf/api"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/metadata"
)

var (
testServiceHash hash.Hash
)
var testServiceHash hash.Hash

func testService(t *testing.T) {
req := readCreateServiceRequest("testdata/test-service.json")
req := newTestCreateServiceRequest()

t.Run("create", func(t *testing.T) {
ctx := metadata.NewOutgoingContext(context.Background(), passmd)

resp, err := client.ServiceClient.Create(ctx, req)
resp, err := client.ServiceClient.Create(context.Background(), req)
require.NoError(t, err)

testServiceHash = resp.Hash
})

t.Run("get", func(t *testing.T) {
ctx := metadata.NewOutgoingContext(context.Background(), passmd)

service, err := client.ServiceClient.Get(ctx, &pb.GetServiceRequest{Hash: testServiceHash})
service, err := client.ServiceClient.Get(context.Background(), &pb.GetServiceRequest{Hash: testServiceHash})
require.NoError(t, err)
require.Equal(t, testServiceHash, service.Hash)
})
Expand All @@ -59,16 +48,3 @@ func testService(t *testing.T) {
require.Equal(t, testServiceHash, resp.Hash)
})
}

func readCreateServiceRequest(filename string) *pb.CreateServiceRequest {
b, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatal(err)
}

var req pb.CreateServiceRequest
if err = json.Unmarshal(b, &req); err != nil {
log.Fatal(err)
}
return &req
}
7 changes: 7 additions & 0 deletions e2e/testdata/test-complex-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM golang:1.13
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o "mesg-test"
CMD [ "./mesg-test" ]
8 changes: 8 additions & 0 deletions e2e/testdata/test-complex-service/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module main

go 1.13

require (
github.com/mesg-foundation/engine v0.15.0
google.golang.org/grpc v1.24.0
)
Loading