api/events: split event types from events service

To avoid importing all of grpc when consuming events, the types of
events have been split in to a separate package. This should allow a
reduction in memory usage in cases where a package is consuming events
but not using the gprc service directly.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day
2017-11-16 12:46:35 -08:00
parent f49b1b7179
commit 09b5ca1072
31 changed files with 1038 additions and 1020 deletions

View File

@@ -8,6 +8,7 @@ import (
"testing"
"time"
eventstypes "github.com/containerd/containerd/api/events"
v1 "github.com/containerd/containerd/api/services/events/v1"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/events"
@@ -19,9 +20,9 @@ import (
func TestExchangeBasic(t *testing.T) {
ctx := namespaces.WithNamespace(context.Background(), t.Name())
testevents := []events.Event{
&v1.ContainerCreate{ID: "asdf"},
&v1.ContainerCreate{ID: "qwer"},
&v1.ContainerCreate{ID: "zxcv"},
&eventstypes.ContainerCreate{ID: "asdf"},
&eventstypes.ContainerCreate{ID: "qwer"},
&eventstypes.ContainerCreate{ID: "zxcv"},
}
exchange := NewExchange()
@@ -80,7 +81,7 @@ func TestExchangeBasic(t *testing.T) {
if err != nil {
t.Fatal(err)
}
received = append(received, ev.(*v1.ContainerCreate))
received = append(received, ev.(*eventstypes.ContainerCreate))
case err := <-subscriber.errq:
if err != nil {
t.Fatal(err)
@@ -118,7 +119,7 @@ func TestExchangeValidateTopic(t *testing.T) {
},
} {
t.Run(testcase.input, func(t *testing.T) {
event := &v1.ContainerCreate{ID: t.Name()}
event := &eventstypes.ContainerCreate{ID: t.Name()}
if err := exchange.Publish(ctx, testcase.input, event); errors.Cause(err) != testcase.err {
if err == nil {
t.Fatalf("expected error %v, received nil", testcase.err)