Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

timecraft: add integration test suite #37

Merged
merged 2 commits into from
May 31, 2023
Merged

Conversation

achille-roussel
Copy link
Contributor

This PR sets up the infrastructure for integrations tests which exercise the main timecraft program, and

I moved the files from internal/cmd back into the top-level directory because I couldn't test the command by invoking cmd.Root because in some error cases the function calls os.Exit which is not permitted during a Go test, moving the tests exercising a compiled binary to internal/cmd did not feel right, and keeping the source and tests close seems like a better setup. We can move the sources back later if we address the os.Exit calls. Note that all the symbols are unexported and in the main package, so they cannot be imported by external Go packages.

I added tests for some of the commands but the test suite is not complete. It is already taking close to 1s to run, I believe this is likely due to recompiling the test wasm program in each test invoking timecraft run, I'll look into leveraging the caching capabilities of wazero to speed this up.

I made a few other changes as well, most are consistency and usability fixes that were highlighted by the test suite. I also added a --quiet option to simplify the text output to a single column of IDs, which is useful to implement script-like operations in tests that involve multiple invocations of the timecraft command.

@@ -29,10 +29,10 @@ Options:
-c, --config Path to the timecraft configuration file (overrides TIMECRAFTCONFIG)
-D, --dial addr Expose a socket connected to the specified address
-e, --env name=value Pass an environment variable to the guest module
--fly-blind Disable recording of the guest module execution
Copy link
Contributor

Choose a reason for hiding this comment

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

🙈

Signed-off-by: Achille Roussel <[email protected]>
@Pryz
Copy link
Contributor

Pryz commented May 31, 2023

Curious why not follow the classic cmd folder like in any other project?

@achille-roussel
Copy link
Contributor Author

Since this is intended to be a command, I want go install github.com/stealthrocket/timecraft to work.

If the main package is in a subdirectory, we need to do go install github.com/stealthrocket/timecraft/cmd/timecraft which is extra details that the user needs to know about the project layout to successfully build and install the program. go install happily says nothing when installing a non-main package, so it creates a pretty bad UX as the command appears to succeed but the program isn't actually installed.

@achille-roussel achille-roussel merged commit 3fa01f8 into main May 31, 2023
3 checks passed
@achille-roussel achille-roussel deleted the integration-tests branch May 31, 2023 16:48
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants