Add unit test.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu
2017-05-16 19:49:07 +00:00
parent 6ac71e5862
commit 322b6ef333
11 changed files with 1633 additions and 15 deletions

View File

@@ -51,7 +51,10 @@ type EventClient struct {
// Recv is a test implementation of Recv
func (cli *EventClient) Recv() (*container.Event, error) {
event := <-cli.Events
event, ok := <-cli.Events
if !ok {
return nil, fmt.Errorf("event channel closed")
}
return event, nil
}
@@ -76,6 +79,18 @@ func NewFakeExecutionClient() *FakeExecutionClient {
}
}
// Stop the fake execution service. Needed when event is enabled.
func (f *FakeExecutionClient) Stop() {
if f.eventsQueue != nil {
close(f.eventsQueue)
}
f.Lock()
defer f.Unlock()
for _, client := range f.eventClients {
close(client.Events)
}
}
// WithEvents setup events publisher for FakeExecutionClient
func (f *FakeExecutionClient) WithEvents() *FakeExecutionClient {
f.eventsQueue = make(chan *container.Event, 1024)
@@ -154,6 +169,13 @@ func (f *FakeExecutionClient) GetCalledNames() []string {
return names
}
// ClearCalls clear all call detail.
func (f *FakeExecutionClient) ClearCalls() {
f.Lock()
defer f.Unlock()
f.called = []CalledDetail{}
}
// GetCalledDetails get detail of each call.
func (f *FakeExecutionClient) GetCalledDetails() []CalledDetail {
f.Lock()