-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathselftests_test.go
More file actions
68 lines (52 loc) · 1.93 KB
/
Copy pathselftests_test.go
File metadata and controls
68 lines (52 loc) · 1.93 KB
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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
//go:build linux && functionaltests
// Package tests holds tests related files
package tests
import (
"errors"
"testing"
"time"
"github.com/DataDog/datadog-agent/pkg/security/events"
"github.com/DataDog/datadog-agent/pkg/security/secl/rules"
"github.com/DataDog/datadog-agent/pkg/util/log"
"github.com/DataDog/datadog-agent/pkg/util/testutil/flake"
"github.com/avast/retry-go/v4"
"github.com/oliveagle/jsonpath"
"github.com/stretchr/testify/assert"
)
func TestSelfTests(t *testing.T) {
SkipIfNotAvailable(t)
flake.MarkOnJobName(t, "ubuntu_25.10")
test, err := newTestModule(t, nil, []*rules.RuleDefinition{}, withStaticOpts(testOpts{enableSelfTests: true}))
if err != nil {
t.Fatal(err)
}
defer test.Close()
test.msgSender.flush()
err = retry.Do(func() error {
msg := test.msgSender.getMsg(events.SelfTestRuleID)
if msg == nil {
return errors.New("self_test event not found")
}
log.Debug("self_tests event tags:", msg.Tags)
assert.NotEmpty(t, msg.Tags, "event's tags are empty")
jsonPathValidation(test, msg.Data, func(_ *testModule, obj interface{}) {
succeededTests, err := jsonpath.JsonPathLookup(obj, `$.succeeded_tests`)
if err != nil {
t.Errorf("could not get succeeded_tests field: %v", err)
}
failedTests, err := jsonpath.JsonPathLookup(obj, `$.failed_tests`)
if err != nil {
t.Errorf("could not get failed_tests field: %v", err)
}
if len(succeededTests.([]interface{})) != 3 || len(failedTests.([]interface{})) > 0 {
t.Errorf("test results: successes: %v, fails: %v", succeededTests, failedTests)
}
})
return nil
}, retry.Attempts(20), retry.Delay(2*time.Second), retry.DelayType(retry.FixedDelay))
assert.NoError(t, err)
}