summaryrefslogtreecommitdiff
path: root/integrationtests/expectations_test.go
blob: 9630cf90ac3bfc72a281c7bd6762b0503a09d946 (plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package integrationtests

import (
	"testing"

	"ior/internal/flamegraph"
	"ior/internal/types"
)

func TestAssertEventsAbsentNoMatch(t *testing.T) {
	result := TestResult{
		Records: []flamegraph.IterRecord{
			{Path: "/tmp/testfile.txt", TraceID: types.SYS_ENTER_OPENAT, Comm: "ioworkload"},
		},
	}

	mt := &testing.T{}
	AssertEventsAbsent(mt, result, []ExpectedEvent{
		{PathContains: "missing.txt"},
	})
	if mt.Failed() {
		t.Error("AssertEventsAbsent should not fail when event is absent")
	}
}

func TestAssertEventsAbsentWithMatch(t *testing.T) {
	result := TestResult{
		Records: []flamegraph.IterRecord{
			{Path: "/tmp/testfile.txt", TraceID: types.SYS_ENTER_OPENAT, Comm: "ioworkload"},
		},
	}

	mt := &testing.T{}
	AssertEventsAbsent(mt, result, []ExpectedEvent{
		{PathContains: "testfile.txt"},
	})
	if !mt.Failed() {
		t.Error("AssertEventsAbsent should fail when event is present")
	}
}

func TestAssertEventsAbsentEmptyResult(t *testing.T) {
	result := TestResult{}

	mt := &testing.T{}
	AssertEventsAbsent(mt, result, []ExpectedEvent{
		{PathContains: "anything.txt"},
	})
	if mt.Failed() {
		t.Error("AssertEventsAbsent should not fail on empty result")
	}
}

func TestAssertEventsAbsentMultiField(t *testing.T) {
	result := TestResult{
		Records: []flamegraph.IterRecord{
			{Path: "/tmp/testfile.txt", TraceID: types.SYS_ENTER_OPENAT, Comm: "ioworkload"},
			{Path: "/tmp/testfile.txt", TraceID: types.SYS_ENTER_WRITE, Comm: "ioworkload"},
		},
	}

	// Multi-field match: path + tracepoint + comm — all match first record.
	mt := &testing.T{}
	AssertEventsAbsent(mt, result, []ExpectedEvent{
		{PathContains: "testfile.txt", Tracepoint: "enter_openat", Comm: "ioworkload"},
	})
	if !mt.Failed() {
		t.Error("AssertEventsAbsent should fail when multi-field event matches")
	}

	// Multi-field partial mismatch: path matches but tracepoint doesn't.
	mt2 := &testing.T{}
	AssertEventsAbsent(mt2, result, []ExpectedEvent{
		{PathContains: "testfile.txt", Tracepoint: "enter_read"},
	})
	if mt2.Failed() {
		t.Error("AssertEventsAbsent should pass when multi-field expectation partially mismatches")
	}
}

func TestAssertEventsAbsentMultipleExpectations(t *testing.T) {
	result := TestResult{
		Records: []flamegraph.IterRecord{
			{Path: "/tmp/found.txt", TraceID: types.SYS_ENTER_OPENAT, Comm: "ioworkload"},
		},
	}

	// First expectation absent, second present — should fail.
	mt := &testing.T{}
	AssertEventsAbsent(mt, result, []ExpectedEvent{
		{PathContains: "missing.txt"},
		{PathContains: "found.txt"},
	})
	if !mt.Failed() {
		t.Error("AssertEventsAbsent should fail when any expectation matches")
	}
}

func TestAssertEventsAbsentRejectsZeroValue(t *testing.T) {
	result := TestResult{
		Records: []flamegraph.IterRecord{
			{Path: "/tmp/testfile.txt", TraceID: types.SYS_ENTER_OPENAT, Comm: "ioworkload"},
		},
	}

	// Zero-value ExpectedEvent should be rejected with an error.
	mt := &testing.T{}
	AssertEventsAbsent(mt, result, []ExpectedEvent{{}})
	if !mt.Failed() {
		t.Error("AssertEventsAbsent should reject zero-value ExpectedEvent")
	}
}