|
|
|
|
@ -20,6 +20,92 @@ import ( |
|
|
|
|
"github.com/stretchr/testify/require" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func TestQuery_GetLogEvents(t *testing.T) { |
|
|
|
|
origNewCWLogsClient := NewCWLogsClient |
|
|
|
|
t.Cleanup(func() { |
|
|
|
|
NewCWLogsClient = origNewCWLogsClient |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
var cli fakeCWLogsClient |
|
|
|
|
|
|
|
|
|
NewCWLogsClient = func(sess *session.Session) cloudwatchlogsiface.CloudWatchLogsAPI { |
|
|
|
|
return &cli |
|
|
|
|
} |
|
|
|
|
const refID = "A" |
|
|
|
|
|
|
|
|
|
testCases := map[string]struct { |
|
|
|
|
query string |
|
|
|
|
expectedInput []*cloudwatchlogs.GetLogEventsInput |
|
|
|
|
}{ |
|
|
|
|
"Nil startTime": { |
|
|
|
|
query: `{ |
|
|
|
|
"type": "logAction", |
|
|
|
|
"subtype": "GetLogEvents", |
|
|
|
|
"logGroupName": "foo", |
|
|
|
|
"logStreamName": "bar", |
|
|
|
|
"endTime": 1, |
|
|
|
|
"startFromHead": false |
|
|
|
|
}`, |
|
|
|
|
expectedInput: []*cloudwatchlogs.GetLogEventsInput{ |
|
|
|
|
{ |
|
|
|
|
EndTime: aws.Int64(1), |
|
|
|
|
Limit: aws.Int64(10), |
|
|
|
|
LogGroupName: aws.String("foo"), |
|
|
|
|
LogStreamName: aws.String("bar"), |
|
|
|
|
StartFromHead: aws.Bool(false), |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
"Nil endTime": { |
|
|
|
|
query: `{ |
|
|
|
|
"type": "logAction", |
|
|
|
|
"subtype": "GetLogEvents", |
|
|
|
|
"logGroupName": "foo", |
|
|
|
|
"logStreamName": "bar", |
|
|
|
|
"startTime": 1, |
|
|
|
|
"startFromHead": true |
|
|
|
|
}`, |
|
|
|
|
expectedInput: []*cloudwatchlogs.GetLogEventsInput{ |
|
|
|
|
{ |
|
|
|
|
StartTime: aws.Int64(1), |
|
|
|
|
Limit: aws.Int64(10), |
|
|
|
|
LogGroupName: aws.String("foo"), |
|
|
|
|
LogStreamName: aws.String("bar"), |
|
|
|
|
StartFromHead: aws.Bool(true), |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for name, test := range testCases { |
|
|
|
|
t.Run(name, func(t *testing.T) { |
|
|
|
|
cli = fakeCWLogsClient{} |
|
|
|
|
|
|
|
|
|
im := datasource.NewInstanceManager(func(s backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) { |
|
|
|
|
return datasourceInfo{}, nil |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
executor := newExecutor(im, newTestConfig(), &fakeSessionCache{}, featuremgmt.WithFeatures()) |
|
|
|
|
_, err := executor.QueryData(context.Background(), &backend.QueryDataRequest{ |
|
|
|
|
PluginContext: backend.PluginContext{ |
|
|
|
|
DataSourceInstanceSettings: &backend.DataSourceInstanceSettings{}, |
|
|
|
|
}, |
|
|
|
|
Queries: []backend.DataQuery{ |
|
|
|
|
{ |
|
|
|
|
RefID: refID, |
|
|
|
|
TimeRange: backend.TimeRange{From: time.Unix(0, 0), To: time.Unix(1, 0)}, |
|
|
|
|
JSON: json.RawMessage(test.query), |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
require.NoError(t, err) |
|
|
|
|
require.Len(t, cli.calls.getEventsWithContext, 1) |
|
|
|
|
assert.Equal(t, test.expectedInput, cli.calls.getEventsWithContext) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestQuery_DescribeLogGroups(t *testing.T) { |
|
|
|
|
origNewCWLogsClient := NewCWLogsClient |
|
|
|
|
t.Cleanup(func() { |
|
|
|
|
|