Skip to content

test: add tests for gadget filter types - #52

Open
mrhapile wants to merge 1 commit into
inspektor-gadget:mainfrom
mrhapile:test/filter-types
Open

test: add tests for gadget filter types#52
mrhapile wants to merge 1 commit into
inspektor-gadget:mainfrom
mrhapile:test/filter-types

Conversation

@mrhapile

@mrhapile mrhapile commented Mar 7, 2026

Copy link
Copy Markdown

Add tests for gadget filter types

ref #20

This PR adds a test file for the filter type definitions and helper logic implemented in src/gadgets/filter_types.tsx.

The tests validate that the exported filter types and related helper functions behave as expected and handle edge cases safely. These tests follow the existing testing conventions used in the repository and help improve overall test coverage for the gadgets module.

How to use

Reviewers can validate this PR by running the test suite locally.

Steps:

  1. Checkout this branch.
  2. Install dependencies if required.
  3. Run the test suite.

Testing done

Commands executed:

npm install
npm test

Result:

Screenshot 2026-03-08 at 12 23 16 AM

The test suite runs successfully and the new test file src/gadgets/filter_types.test.tsx executes without errors.

Signed-off-by: mrhapile <allinonegaming3456@gmail.com>
Copilot AI review requested due to automatic review settings March 7, 2026 18:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds initial unit test coverage for gadget filter type definitions in the gadgets module (ref #20), ensuring the exported FILTERS_TYPE mapping stays consistent.

Changes:

  • Added a new Vitest test file verifying the shape/values of FILTERS_TYPE entries (uint32/int32/string/bool/[]string).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@@ -0,0 +1,39 @@
/** @vitest-environment jsdom */

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file-level @vitest-environment jsdom directive looks unnecessary here since these assertions only exercise a plain object and don’t touch DOM APIs. Consider removing it (or using the default/node environment) to keep test startup lighter and avoid coupling this unit test to jsdom.

Suggested change
/** @vitest-environment jsdom */

Copilot uses AI. Check for mistakes.
Comment on lines +6 to +38
test('exports FILTERS_TYPE constant', () => {
expect(FILTERS_TYPE).toBeDefined();
expect(typeof FILTERS_TYPE).toBe('object');
});

test('uint32 filter is mapped correctly', () => {
expect(FILTERS_TYPE.uint32).toBeDefined();
expect(FILTERS_TYPE.uint32.type).toBe('number');
expect(FILTERS_TYPE.uint32.max).toBe(4294967295);
expect(FILTERS_TYPE.uint32.min).toBe(0);
});

test('int32 filter is mapped correctly', () => {
expect(FILTERS_TYPE.int32).toBeDefined();
expect(FILTERS_TYPE.int32.type).toBe('number');
expect(FILTERS_TYPE.int32.max).toBe(2147483647);
expect(FILTERS_TYPE.int32.min).toBe(-2147483648);
});

test('string filter is mapped correctly', () => {
expect(FILTERS_TYPE.string).toBeDefined();
expect(FILTERS_TYPE.string.type).toBe('string');
});

test('bool filter is mapped correctly', () => {
expect(FILTERS_TYPE.bool).toBeDefined();
expect(FILTERS_TYPE.bool.type).toBe('checkbox');
});

test('[]string filter is mapped correctly', () => {
expect(FILTERS_TYPE['[]string']).toBeDefined();
expect(FILTERS_TYPE['[]string'].type).toBe('string');
});

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation in this test file doesn’t match the repository’s typical 2-space formatting (e.g., other TS/TSX files in src/gadgets). Running the formatter (or adjusting indentation) will keep the codebase style-consistent.

Suggested change
test('exports FILTERS_TYPE constant', () => {
expect(FILTERS_TYPE).toBeDefined();
expect(typeof FILTERS_TYPE).toBe('object');
});
test('uint32 filter is mapped correctly', () => {
expect(FILTERS_TYPE.uint32).toBeDefined();
expect(FILTERS_TYPE.uint32.type).toBe('number');
expect(FILTERS_TYPE.uint32.max).toBe(4294967295);
expect(FILTERS_TYPE.uint32.min).toBe(0);
});
test('int32 filter is mapped correctly', () => {
expect(FILTERS_TYPE.int32).toBeDefined();
expect(FILTERS_TYPE.int32.type).toBe('number');
expect(FILTERS_TYPE.int32.max).toBe(2147483647);
expect(FILTERS_TYPE.int32.min).toBe(-2147483648);
});
test('string filter is mapped correctly', () => {
expect(FILTERS_TYPE.string).toBeDefined();
expect(FILTERS_TYPE.string.type).toBe('string');
});
test('bool filter is mapped correctly', () => {
expect(FILTERS_TYPE.bool).toBeDefined();
expect(FILTERS_TYPE.bool.type).toBe('checkbox');
});
test('[]string filter is mapped correctly', () => {
expect(FILTERS_TYPE['[]string']).toBeDefined();
expect(FILTERS_TYPE['[]string'].type).toBe('string');
});
test('exports FILTERS_TYPE constant', () => {
expect(FILTERS_TYPE).toBeDefined();
expect(typeof FILTERS_TYPE).toBe('object');
});
test('uint32 filter is mapped correctly', () => {
expect(FILTERS_TYPE.uint32).toBeDefined();
expect(FILTERS_TYPE.uint32.type).toBe('number');
expect(FILTERS_TYPE.uint32.max).toBe(4294967295);
expect(FILTERS_TYPE.uint32.min).toBe(0);
});
test('int32 filter is mapped correctly', () => {
expect(FILTERS_TYPE.int32).toBeDefined();
expect(FILTERS_TYPE.int32.type).toBe('number');
expect(FILTERS_TYPE.int32.max).toBe(2147483647);
expect(FILTERS_TYPE.int32.min).toBe(-2147483648);
});
test('string filter is mapped correctly', () => {
expect(FILTERS_TYPE.string).toBeDefined();
expect(FILTERS_TYPE.string.type).toBe('string');
});
test('bool filter is mapped correctly', () => {
expect(FILTERS_TYPE.bool).toBeDefined();
expect(FILTERS_TYPE.bool.type).toBe('checkbox');
});
test('[]string filter is mapped correctly', () => {
expect(FILTERS_TYPE['[]string']).toBeDefined();
expect(FILTERS_TYPE['[]string'].type).toBe('string');
});

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +6
import { FILTERS_TYPE } from './filter_types';

describe('gadget filter types', () => {
test('exports FILTERS_TYPE constant', () => {

Copilot AI Mar 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description mentions “helper logic” and “edge cases”, but this test file only validates the FILTERS_TYPE constant values. Either update the PR description to match what’s being tested, or add tests for the referenced helper behavior (if it exists elsewhere).

Copilot uses AI. Check for mistakes.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@illume illume left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contributions!

Please let us know if you want to continue this by addressing the review comments? If not that's ok, we can take over the PR (and finish it or close it ourselves).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants