1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
package integration
import (
"github.com/stretchr/testify/assert"
"github.com/zorkian/go-datadog-api"
"testing"
)
func TestLogsIndexGet(t *testing.T) {
logsIndex, err := client.GetLogsIndex("main")
assert.Nil(t, err)
updateLogsIndex := datadog.LogsIndex{
Filter: &datadog.FilterConfiguration{Query: datadog.String("updated query")},
ExclusionFilters: []datadog.ExclusionFilter{
{
Name: datadog.String("updated Filter 1"),
IsEnabled: datadog.Bool(false),
Filter: &datadog.Filter{
Query: datadog.String("source:agent"),
SampleRate: datadog.Float64(0.3),
},
}, {
Name: datadog.String("updated Filter 2"),
IsEnabled: datadog.Bool(false),
Filter: &datadog.Filter{
Query: datadog.String("source:info"),
SampleRate: datadog.Float64(0.2),
},
}, {
Name: datadog.String("updated Filter 3"),
IsEnabled: datadog.Bool(false),
Filter: &datadog.Filter{
Query: datadog.String("source:warn"),
SampleRate: datadog.Float64(1.0),
},
},
},
}
updatedLogsIndex, err := client.UpdateLogsIndex(*logsIndex.Name, &updateLogsIndex)
defer assertRevertChange(t, logsIndex)
assert.Nil(t, err)
assert.Equal(t, &datadog.LogsIndex{
Name: logsIndex.Name,
NumRetentionDays: logsIndex.NumRetentionDays,
DailyLimit: logsIndex.DailyLimit,
IsRateLimited: logsIndex.IsRateLimited,
Filter: updateLogsIndex.Filter,
ExclusionFilters: updateLogsIndex.ExclusionFilters,
}, updatedLogsIndex)
}
func TestUpdateIndexList(t *testing.T) {
indexList, err := client.GetLogsIndexList()
assert.Nil(t, err)
size := len(indexList.IndexNames)
updateList := make([]string, size)
for i, name := range indexList.IndexNames {
updateList[size-1-i] = name
}
updateIndexList := &datadog.LogsIndexList{IndexNames: updateList}
updatedIndexList, err := client.UpdateLogsIndexList(updateIndexList)
defer assertRevertOrder(t, indexList)
assert.Nil(t, err)
assert.Equal(t, updateIndexList, updatedIndexList)
}
func assertRevertOrder(t *testing.T, indexList *datadog.LogsIndexList) {
revertedList, err := client.UpdateLogsIndexList(indexList)
assert.Nil(t, err)
assert.Equal(t, indexList, revertedList)
}
func assertRevertChange(t *testing.T, logsIndex *datadog.LogsIndex) {
revertLogsIndex, err := client.UpdateLogsIndex(*logsIndex.Name, &datadog.LogsIndex{
Filter: logsIndex.Filter,
ExclusionFilters: logsIndex.ExclusionFilters,
})
assert.Nil(t, err)
assert.Equal(t, revertLogsIndex, logsIndex)
}
|