File: logs_indexes_test.go

package info (click to toggle)
golang-github-zorkian-go-datadog-api 2.30.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 1,612 kB
  • sloc: makefile: 28; sh: 13
file content (63 lines) | stat: -rw-r--r-- 1,444 bytes parent folder | download
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
package datadog

import (
	"github.com/stretchr/testify/assert"
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"testing"
)

func TestLogsIndexGet(t *testing.T) {
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		response, err := ioutil.ReadFile("./tests/fixtures/logs/index_response.json")
		if err != nil {
			t.Fatal(err)
		}
		w.Write(response)
	}))

	defer ts.Close()

	client := Client{
		baseUrl:           ts.URL,
		HttpClient:        http.DefaultClient,
		rateLimitingStats: make(map[string]RateLimit),
	}

	logsIndex, err := client.GetLogsIndex("main")
	assert.Nil(t, err)
	assert.Equal(t, expectedIndex, logsIndex)
}

var expectedIndex = &LogsIndex{
	Name:             String("main"),
	NumRetentionDays: Int64(90),
	DailyLimit:       Int64(151000000),
	IsRateLimited:    Bool(false),
	Filter:           &FilterConfiguration{Query: String("*")},
	ExclusionFilters: []ExclusionFilter{
		{
			Name:      String("Filter 1"),
			IsEnabled: Bool(true),
			Filter: &Filter{
				Query:      String("source:agent status:info"),
				SampleRate: Float64(1.0),
			},
		}, {
			Name:      String("Filter 2"),
			IsEnabled: Bool(true),
			Filter: &Filter{
				Query:      String("source:agent"),
				SampleRate: Float64(0.8),
			},
		}, {
			Name:      String("Filter 3"),
			IsEnabled: Bool(true),
			Filter: &Filter{
				Query:      String("source:debug"),
				SampleRate: Float64(0.5),
			},
		},
	},
}