gopkg.in/dotcloud/docker.v1@v1.13.1/daemon/logger/awslogs/cwlogsiface_mock_test.go (about) 1 package awslogs 2 3 import "github.com/aws/aws-sdk-go/service/cloudwatchlogs" 4 5 type mockcwlogsclient struct { 6 createLogStreamArgument chan *cloudwatchlogs.CreateLogStreamInput 7 createLogStreamResult chan *createLogStreamResult 8 putLogEventsArgument chan *cloudwatchlogs.PutLogEventsInput 9 putLogEventsResult chan *putLogEventsResult 10 } 11 12 type createLogStreamResult struct { 13 successResult *cloudwatchlogs.CreateLogStreamOutput 14 errorResult error 15 } 16 17 type putLogEventsResult struct { 18 successResult *cloudwatchlogs.PutLogEventsOutput 19 errorResult error 20 } 21 22 func newMockClient() *mockcwlogsclient { 23 return &mockcwlogsclient{ 24 createLogStreamArgument: make(chan *cloudwatchlogs.CreateLogStreamInput, 1), 25 createLogStreamResult: make(chan *createLogStreamResult, 1), 26 putLogEventsArgument: make(chan *cloudwatchlogs.PutLogEventsInput, 1), 27 putLogEventsResult: make(chan *putLogEventsResult, 1), 28 } 29 } 30 31 func newMockClientBuffered(buflen int) *mockcwlogsclient { 32 return &mockcwlogsclient{ 33 createLogStreamArgument: make(chan *cloudwatchlogs.CreateLogStreamInput, buflen), 34 createLogStreamResult: make(chan *createLogStreamResult, buflen), 35 putLogEventsArgument: make(chan *cloudwatchlogs.PutLogEventsInput, buflen), 36 putLogEventsResult: make(chan *putLogEventsResult, buflen), 37 } 38 } 39 40 func (m *mockcwlogsclient) CreateLogStream(input *cloudwatchlogs.CreateLogStreamInput) (*cloudwatchlogs.CreateLogStreamOutput, error) { 41 m.createLogStreamArgument <- input 42 output := <-m.createLogStreamResult 43 return output.successResult, output.errorResult 44 } 45 46 func (m *mockcwlogsclient) PutLogEvents(input *cloudwatchlogs.PutLogEventsInput) (*cloudwatchlogs.PutLogEventsOutput, error) { 47 events := make([]*cloudwatchlogs.InputLogEvent, len(input.LogEvents)) 48 copy(events, input.LogEvents) 49 m.putLogEventsArgument <- &cloudwatchlogs.PutLogEventsInput{ 50 LogEvents: events, 51 SequenceToken: input.SequenceToken, 52 LogGroupName: input.LogGroupName, 53 LogStreamName: input.LogStreamName, 54 } 55 output := <-m.putLogEventsResult 56 return output.successResult, output.errorResult 57 } 58 59 type mockmetadataclient struct { 60 regionResult chan *regionResult 61 } 62 63 type regionResult struct { 64 successResult string 65 errorResult error 66 } 67 68 func newMockMetadataClient() *mockmetadataclient { 69 return &mockmetadataclient{ 70 regionResult: make(chan *regionResult, 1), 71 } 72 } 73 74 func (m *mockmetadataclient) Region() (string, error) { 75 output := <-m.regionResult 76 return output.successResult, output.errorResult 77 }