Skip to content

Commit af5fd18

Browse files
committed
add tests
1 parent cb4128e commit af5fd18

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

__tests__/tools/topic_property_extractor.test.js

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,22 @@ describe('topic_property_extractor.py', () => {
1212
// Create a minimal mock Redpanda source tree
1313
if (!fs.existsSync(mockSourcePath)) {
1414
fs.mkdirSync(mockSourcePath, { recursive: true });
15-
// Create a mock header file with a topic property
15+
// Create a mock header file with topic properties and no-op allowlist
1616
const headerDir = path.join(mockSourcePath, 'src/v/kafka/server/handlers/topics');
1717
fs.mkdirSync(headerDir, { recursive: true });
1818
fs.writeFileSync(
1919
path.join(headerDir, 'types.h'),
20-
'inline constexpr std::string_view topic_property_retention_ms = "retention.ms";\n'
20+
`inline constexpr std::string_view topic_property_retention_ms = "retention.ms";
21+
inline constexpr std::string_view topic_property_segment_bytes = "segment.bytes";
22+
inline constexpr std::string_view topic_property_flush_messages = "flush.messages";
23+
24+
// Mock allowlist for no-op properties
25+
inline constexpr std::array<std::string_view, 3> allowlist_topic_noop_confs = {
26+
"flush.messages",
27+
"segment.index.bytes",
28+
"preallocate",
29+
};
30+
`
2131
);
2232
// Add a mock .cc file (should be ignored for property extraction)
2333
fs.writeFileSync(
@@ -29,7 +39,7 @@ describe('topic_property_extractor.py', () => {
2939
fs.mkdirSync(configDir, { recursive: true });
3040
fs.writeFileSync(
3141
path.join(configDir, 'mock_config.cc'),
32-
'config.get("log_retention_ms");\n'
42+
'config.get("log_retention_ms");\nconfig.get("log_segment_size");\n'
3343
);
3444
}
3545
});
@@ -49,10 +59,39 @@ describe('topic_property_extractor.py', () => {
4959
expect(result.topic_properties['retention.ms'].property_name).toBe('retention.ms');
5060
});
5161

52-
it('generates AsciiDoc output', () => {
62+
it('detects no-op properties correctly', () => {
63+
execSync(`python3 ${scriptPath} --source-path ${mockSourcePath} --output-json ${outputJson}`);
64+
const result = JSON.parse(fs.readFileSync(outputJson, 'utf8'));
65+
66+
// Check that noop_properties array is present
67+
expect(result.noop_properties).toBeDefined();
68+
expect(Array.isArray(result.noop_properties)).toBe(true);
69+
expect(result.noop_properties).toContain('flush.messages');
70+
expect(result.noop_properties).toContain('segment.index.bytes');
71+
expect(result.noop_properties).toContain('preallocate');
72+
73+
// Check that flush.messages is marked as no-op
74+
if (result.topic_properties['flush.messages']) {
75+
expect(result.topic_properties['flush.messages'].is_noop).toBe(true);
76+
}
77+
78+
// Check that regular properties are not marked as no-op
79+
expect(result.topic_properties['retention.ms'].is_noop).toBe(false);
80+
expect(result.topic_properties['segment.bytes'].is_noop).toBe(false);
81+
});
82+
83+
it('excludes no-op properties from AsciiDoc generation', () => {
5384
execSync(`python3 ${scriptPath} --source-path ${mockSourcePath} --output-adoc ${outputAdoc}`);
5485
const adoc = fs.readFileSync(outputAdoc, 'utf8');
86+
87+
// Should contain regular properties
5588
expect(adoc).toContain('= Topic Configuration Properties');
5689
expect(adoc).toContain('retention.ms');
90+
expect(adoc).toContain('segment.bytes');
91+
92+
// Should NOT contain no-op properties in documentation
93+
expect(adoc).not.toContain('flush.messages');
94+
expect(adoc).not.toContain('segment.index.bytes');
95+
expect(adoc).not.toContain('preallocate');
5796
});
5897
});

0 commit comments

Comments
 (0)