2015-08-04 20:35:06 -04:00
|
|
|
package awslogs
|
|
|
|
|
|
|
|
import "github.com/aws/aws-sdk-go/service/cloudwatchlogs"
|
|
|
|
|
|
|
|
type mockcwlogsclient struct {
|
|
|
|
createLogStreamArgument chan *cloudwatchlogs.CreateLogStreamInput
|
|
|
|
createLogStreamResult chan *createLogStreamResult
|
|
|
|
putLogEventsArgument chan *cloudwatchlogs.PutLogEventsInput
|
|
|
|
putLogEventsResult chan *putLogEventsResult
|
|
|
|
}
|
|
|
|
|
|
|
|
type createLogStreamResult struct {
|
|
|
|
successResult *cloudwatchlogs.CreateLogStreamOutput
|
|
|
|
errorResult error
|
|
|
|
}
|
|
|
|
|
|
|
|
type putLogEventsResult struct {
|
|
|
|
successResult *cloudwatchlogs.PutLogEventsOutput
|
|
|
|
errorResult error
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMockClient() *mockcwlogsclient {
|
|
|
|
return &mockcwlogsclient{
|
|
|
|
createLogStreamArgument: make(chan *cloudwatchlogs.CreateLogStreamInput, 1),
|
|
|
|
createLogStreamResult: make(chan *createLogStreamResult, 1),
|
|
|
|
putLogEventsArgument: make(chan *cloudwatchlogs.PutLogEventsInput, 1),
|
|
|
|
putLogEventsResult: make(chan *putLogEventsResult, 1),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMockClientBuffered(buflen int) *mockcwlogsclient {
|
|
|
|
return &mockcwlogsclient{
|
|
|
|
createLogStreamArgument: make(chan *cloudwatchlogs.CreateLogStreamInput, buflen),
|
|
|
|
createLogStreamResult: make(chan *createLogStreamResult, buflen),
|
|
|
|
putLogEventsArgument: make(chan *cloudwatchlogs.PutLogEventsInput, buflen),
|
|
|
|
putLogEventsResult: make(chan *putLogEventsResult, buflen),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockcwlogsclient) CreateLogStream(input *cloudwatchlogs.CreateLogStreamInput) (*cloudwatchlogs.CreateLogStreamOutput, error) {
|
|
|
|
m.createLogStreamArgument <- input
|
|
|
|
output := <-m.createLogStreamResult
|
|
|
|
return output.successResult, output.errorResult
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockcwlogsclient) PutLogEvents(input *cloudwatchlogs.PutLogEventsInput) (*cloudwatchlogs.PutLogEventsOutput, error) {
|
2016-05-25 14:50:22 -04:00
|
|
|
events := make([]*cloudwatchlogs.InputLogEvent, len(input.LogEvents))
|
|
|
|
copy(events, input.LogEvents)
|
|
|
|
m.putLogEventsArgument <- &cloudwatchlogs.PutLogEventsInput{
|
|
|
|
LogEvents: events,
|
|
|
|
SequenceToken: input.SequenceToken,
|
|
|
|
LogGroupName: input.LogGroupName,
|
|
|
|
LogStreamName: input.LogStreamName,
|
|
|
|
}
|
2015-08-04 20:35:06 -04:00
|
|
|
output := <-m.putLogEventsResult
|
|
|
|
return output.successResult, output.errorResult
|
|
|
|
}
|
|
|
|
|
2015-09-28 02:40:44 -04:00
|
|
|
type mockmetadataclient struct {
|
|
|
|
regionResult chan *regionResult
|
|
|
|
}
|
|
|
|
|
|
|
|
type regionResult struct {
|
|
|
|
successResult string
|
|
|
|
errorResult error
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMockMetadataClient() *mockmetadataclient {
|
|
|
|
return &mockmetadataclient{
|
|
|
|
regionResult: make(chan *regionResult, 1),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockmetadataclient) Region() (string, error) {
|
|
|
|
output := <-m.regionResult
|
|
|
|
return output.successResult, output.errorResult
|
|
|
|
}
|