Skip to content

Conversation

@nirs
Copy link
Member

@nirs nirs commented Oct 26, 2024

The qemuimg package provides now only qemuimg.Convert(). I plan to add
qemuimg.Create(), qemuimg.Info(), qemuimg.Map(), and qemuimg.Compare().

This makes the code nicer to work with, but adds a test only dependency.
The qcow2reader tests use now qemu2reader_test package, so the
dependency should be built only for tests.

The qemuimg test package will also be useful for other project using
this library, since testing code using the library typically requires
creating, converting and comparing qcow2 images.

go.mod Outdated
// Testing requirements
require github.com/lima-vm/go-qcow2reader/test v0.4.0

replace github.com/lima-vm/go-qcow2reader/test v0.4.0 => ./test
Copy link
Member

@AkihiroSuda AkihiroSuda Oct 28, 2024

Choose a reason for hiding this comment

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

Why this has to be a separate module, not just a separate package?

Copy link
Member Author

Choose a reason for hiding this comment

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

It can be in the package, I tried to avoid building this as part of the go-qcow2reader module. Removing the extra module will make it simpler.

Copy link
Member

@AkihiroSuda AkihiroSuda Oct 28, 2024

Choose a reason for hiding this comment

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

I don't like maintaining multiple modules (with an exception for cmd/go-qcow2reader-example, as it was inevitable for isolating the third-party zstd dependency from the core module).

IIUC, just splitting the package is enough to omit the corresponding object code from the binary of Lima.
Even if it was not enough, the footprint of the object code would be negligible (just a few KiB?)

Copy link
Member Author

Choose a reason for hiding this comment

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

The qemuimg package is tiny. I'll remove the module. Should we keep the test directory to make it more clear that this is a test only code?

Copy link
Member

Choose a reason for hiding this comment

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

Should we keep the test directory to make it more clear that this is a test only code?

Either would be fine

Copy link
Member Author

Choose a reason for hiding this comment

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

Module removed.

@@ -1,26 +1,21 @@
package qcow2reader
package qcow2reader_test
Copy link
Member

Choose a reason for hiding this comment

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

The test should use the same package as the code, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is for whitebox tests that need access to the internals. For blackbox tests, it is better to have the test in the special *_test package. This way we use the code in the same way a user would use the code.

I think the default should be blackbox test, and whitebox tests should be used only if needed.

golang/go#25223

Copy link
Member

@AkihiroSuda AkihiroSuda Oct 28, 2024

Choose a reason for hiding this comment

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

Thanks, could you add that context as a code comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, will add.

Copy link
Member Author

Choose a reason for hiding this comment

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

Add a package comment.

@nirs nirs changed the title Extract qemuimg package in a test module Extract qemuimg test package Nov 1, 2024
@nirs nirs requested a review from AkihiroSuda November 1, 2024 20:46
@@ -1,26 +1,22 @@
package qcow2reader
// package qcow2reader_test keeps blackbox tests for qcow2reader.
Copy link
Member

Choose a reason for hiding this comment

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

nit

Suggested change
// package qcow2reader_test keeps blackbox tests for qcow2reader.
// Package qcow2reader_test keeps blackbox tests for qcow2reader.

https://tip.golang.org/doc/comment

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

The qemuimg package provides now only qemuimg.Convert(). I plan to add
qemuimg.Create(), qemuimg.Info(), qemuimg.Map(), and qemuimg.Compare().

This makes the code nicer to work with, but adds a test only dependency.
The qcow2reader tests use now qemu2reader_test package, so the
dependency should be built only for tests.

The qemuimg test package will also be useful for other project using
this library, since testing code using the library typically requires
creating, converting and comparing qcow2 images.

Signed-off-by: Nir Soffer <[email protected]>
@nirs nirs requested a review from AkihiroSuda November 2, 2024 00:35
Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

@AkihiroSuda AkihiroSuda merged commit 89efe97 into lima-vm:master Nov 2, 2024
2 checks passed
@nirs nirs deleted the qemuimg-package branch November 18, 2024 00:16
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.

2 participants