Skip to content

Feat/add unit tests#395

Merged
cmainas merged 1 commit intourunc-dev:main-pr395from
Mysterio-17:feat/add-unit-tests
Feb 18, 2026
Merged

Feat/add unit tests#395
cmainas merged 1 commit intourunc-dev:main-pr395from
Mysterio-17:feat/add-unit-tests

Conversation

@Mysterio-17
Copy link
Contributor

Add Unit Tests for Vaccel, Network Utils, and Rootfs Selection

Fixes: #96

This PR adds comprehensive unit tests for previously untested functions in the urunc codebase, improving overall test coverage.

Tests Added

pkg/unikontainers/vaccel_test.go (2 test functions, 15 test cases)

  • TestIdToGuestCID - 4 test cases for deterministic vAccel guest CID generation from container IDs
  • TestIsValidVSockAddress - 11 test cases validating vsock addresses for qemu (vsock://) and firecracker (unix://) formats

pkg/unikontainers/rootfs_test.go (3 test functions, 14 test cases)

  • TestNewRootfsResult - 4 test cases for rootfs result creation (initrd, block, 9pfs, empty)
  • TestRootfsSelector_TryInitrd - 3 test cases for annotation-based initrd path detection
  • TestRootfsSelector_ShouldMountContainerRootfs - 7 test cases for boolean parsing (true/1/false/0/invalid/empty values)

pkg/network/network_test.go (3 test functions, 7 test cases)

  • TestGetTapIndex - Tests TAP device index extraction from interface names
  • TestNewNetworkManager - 5 test cases for network manager factory pattern (static/dynamic/invalid)
  • TestEnsureEth0Exists - Tests eth0 interface existence validation

Summary

  • Total: 8 test functions covering 36+ test cases
  • Coverage: Targets previously untested utility functions in vaccel.go, rootfs.go, and network.go
  • All tests passing

@netlify
Copy link

netlify bot commented Jan 24, 2026

Deploy Preview for urunc ready!

Name Link
🔨 Latest commit 014d6d3
🔍 Latest deploy log https://app.netlify.com/projects/urunc/deploys/6995741f196fcb0008bfeae8
😎 Deploy Preview https://deploy-preview-395--urunc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@cmainas
Copy link
Contributor

cmainas commented Jan 26, 2026

Hello @Mysterio-17 ,

this PR also has changes from the netkit PR. These are two different PRs and the same changes should not be present in both PRs. Please remove the netkit changes from this PR and take a look in the contribution guide

@Mysterio-17 Mysterio-17 force-pushed the feat/add-unit-tests branch 2 times, most recently from 31a2818 to 24d5f9f Compare January 26, 2026 09:10
@Mysterio-17
Copy link
Contributor Author

Hello @cmainas , I’ve removed all netkit-related changes from this PR as suggested, and it now includes only unit test additions. All tests pass successfully, and the commit message has been updated to follow the contribution guidelines.
Please let me know if you have any feedback or suggestions.

Copy link
Contributor

@cmainas cmainas left a comment

Choose a reason for hiding this comment

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

Hello @Mysterio-17 ,

thank you for this contribution. I have various comments:

@Mysterio-17
Copy link
Contributor Author

Hello @cmainas,
Thanks for the thorough review! I’ve incorporated all the feedback in the latest commit.

  • I refactored the tests to use github.com/stretchr/testify/assert for cleaner assertions and aligned them with the pattern in config_test.go. I also added t.Parallel() where appropriate to enable parallel execution.
  • I cleaned up a few redundant cases by removing duplicate invalid network type tests (keeping a single representative one), dropping TestEnsureEth0Exists, and simplifying TestNewRootfsResult down to one focused test.
  • For TestIdToGuestCID, I replaced wantMin / wantMax with constants (minCID, maxCID), removed the unused checkCID field and the determinism test, and reduced it to two clear cases that directly validate the expected return values.
  • I also updated TestIsValidVSockAddress by renaming hypervisor to monitor, adding an expectedPath check for the qemu case, and renaming “unsupported hypervisor” to “unsupported monitor” for clarity.

All tests are passing now. Please let me know if any further changes are needed.

Copy link
Contributor

@cmainas cmainas left a comment

Choose a reason for hiding this comment

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

Hello @Mysterio-17 ,

thank you for the changes. I have left a few comments. Furthermore, there are two more things that we need to take into consideration:

  • We need to add the network_test as a target for init testing in the makefile
  • The isValidSockAddress function can change the rpcAddress and hence we need to check its value after the call to that function.

@Mysterio-17
Copy link
Contributor Author

Hello @cmainas ,
Thanks for the feedback! I've made the changes:

  • Removed TestGetTapIndex since it depends on host interfaces.
  • Fixed TestIdToGuestCID to use actual expected values instead of calling the function.
  • Added check for rpcAddress modification in TestIsValidVSockAddress.
  • Added test_network to the Makefile unittest target.

I've run the tests locally, let me know if any changes are required more

@cmainas
Copy link
Contributor

cmainas commented Feb 6, 2026

Hello @Mysterio-17 ,

unfortunately, there are still some linting errors that need to be fixed.

@Mysterio-17
Copy link
Contributor Author

Hi @cmainas , I tried fixing the linting errors locally, kindly run tests once more so that i can check the issues, if any

@cmainas
Copy link
Contributor

cmainas commented Feb 9, 2026

Hello @Mysterio-17 ,

could you please squash your commits? There are commits for netkit and for small changes which do not add value in the commit history. Also, there are still linting issues. You can execute the linter locally with make lint

@Mysterio-17
Copy link
Contributor Author

Hello @cmainas , I've squashed all commits into a single clean commit and removed all netkit and unnecessary references from the commit history. I also executed the linter locally, Could you please run the tests again

@cmainas
Copy link
Contributor

cmainas commented Feb 10, 2026

Hello @Mysterio-17 there are some issues with the commit message

✖   header must not be longer than 72 characters, current length is 75 [header-max-length]
✖   body may not be misspelled: subtests [spellcheck/body]

Also, do not forget to rebase with the main branch of urunc

@Mysterio-17 Mysterio-17 force-pushed the feat/add-unit-tests branch 2 times, most recently from 0ce55b6 to 425703c Compare February 11, 2026 16:00
@Mysterio-17
Copy link
Contributor Author

Sure @cmainas , I fixed the header and mispelling and also rebased it with the main branch

Copy link
Contributor

@cmainas cmainas left a comment

Choose a reason for hiding this comment

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

Hello @Mysterio-17 ,

I checked the code and I found some small things that need to get addressed.

@Mysterio-17
Copy link
Contributor Author

Hello @cmainas ,
I've addressed the changes, network_test.go now uses the expectedType field to verify the returned type matches expectations and vaccel_test.go removed redundant range checks, the exact value assertion implicitly validates the limits.
Let me know if any other changes are rerquired.

@cmainas
Copy link
Contributor

cmainas commented Feb 13, 2026

Hello @Mysterio-17 ,

now there are multiple new files in this PR, which are unrelated to the PR.

@Mysterio-17 Mysterio-17 force-pushed the feat/add-unit-tests branch 3 times, most recently from 6b0ac25 to 66e7d74 Compare February 13, 2026 08:19
@Mysterio-17
Copy link
Contributor Author

Hello @cmainas , I apologize for the inconvenience caused by including unrelated files in the previous commits. I have now cleaned the commit history to remove all unrelated files and rebased the branch to resolve the merge conflicts. The PR now contains only the relevant unit test files.

@Mysterio-17
Copy link
Contributor Author

Hello @cmainas , I've made the changes, Kindly have a look at this.

@Mysterio-17
Copy link
Contributor Author

Hello @cmainas , I've removed the unused expectedType field as suggested.

@cmainas
Copy link
Contributor

cmainas commented Feb 17, 2026

Hello @Mysterio-17 , the changes look ok.

However, for the merge, please:

@Mysterio-17
Copy link
Contributor Author

Mysterio-17 commented Feb 17, 2026

Hello @cmainas , I've addressed the feedback: added myself to contributors.yaml, fixed the linting error (changed "tests" to "test"), rebased on main, and squashed into a single commit. Kindly have a look at it.

Copy link
Contributor

@IrvingMg IrvingMg left a comment

Choose a reason for hiding this comment

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

Hey @Mysterio-17, it looks like something got mixed up here. The rebase/squash may have introduced some unintended changes, including several typos, version downgrades, and some reverted changes. Could you please review it?

FYI: It might be better to fix the rebase first, which should resolve my comments automatically.

@Mysterio-17
Copy link
Contributor Author

Hello @cmainas @IrvingMg , I've fixed the rebase, the PR now only contains the 3 test files and contributors.yaml, which should resolve all the typo/downgrade comments automatically.

@urunc-bot urunc-bot bot changed the base branch from main to main-pr395 February 18, 2026 07:25
Copy link
Contributor

@cmainas cmainas left a comment

Choose a reason for hiding this comment

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

Thank you @Mysterio-17 for the changes.

@cmainas
Copy link
Contributor

cmainas commented Feb 18, 2026

Sorry for the approval, I thought the tests have been executed. There are some issues with the commit linter. Also, the target for the unit test in the Makefile got removed. Please try to do the changes manually and not with a tool.

@cmainas cmainas changed the base branch from main-pr395 to main February 18, 2026 07:40
Add unit tests for network, rootfs and vaccel.

Signed-off-by: Mradul Tiwari <mradultiwari1708@gmail.com>
@Mysterio-17
Copy link
Contributor Author

Hello @cmainas , I've fixed the rebase to include only the relevant files, shortened the commit message to pass linting, and added test_network target to Makefile.

@urunc-bot urunc-bot bot changed the base branch from main to main-pr395 February 18, 2026 09:12
Copy link
Contributor

@cmainas cmainas left a comment

Choose a reason for hiding this comment

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

Thank you @Mysterio-17

@cmainas cmainas merged commit ccf7b1a into urunc-dev:main-pr395 Feb 18, 2026
33 checks passed
github-actions bot pushed a commit that referenced this pull request Feb 18, 2026
Add unit tests for network, rootfs and vaccel.

PR: #395
Signed-off-by: Mradul Tiwari <mradultiwari1708@gmail.com>
Reviewed-by: Irving Mondragón <mirvingr@gmail.com>
Reviewed-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Approved-by: Charalampos Mainas <cmainas@nubificus.co.uk>
urunc-bot bot pushed a commit that referenced this pull request Feb 18, 2026
Add unit tests for network, rootfs and vaccel.

PR: #395
Signed-off-by: Mradul Tiwari <mradultiwari1708@gmail.com>
Reviewed-by: Irving Mondragón <mirvingr@gmail.com>
Reviewed-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Approved-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add more unit tests

3 participants