lula icon indicating copy to clipboard operation
lula copied to clipboard

fix: 47 add automated tests (partially)

Open CloudBeard opened this issue 1 year ago • 3 comments

Add some unit tests for the uuid command and tools command.

Did not add for for lint. Need to wait for a new release of go-oscal and rework it after we bump the dependency. Issues with the way it handles errors currently so it breaks tests.

Didn't add for the lula validate command since the oscal version may/will change.

Will add those in a separate PR.

Created a lulatest package to house some common variables and functions that may make testing long term more uniform. Copied a lot of how go-oscal is setup too to keep tools uniform.

Did not update the makefile to include the unit tests as the makefile in main will grab all ready.

CloudBeard avatar Dec 15 '23 18:12 CloudBeard

Deploy Preview for lula-docs canceled.

Name Link
Latest commit 7cc2c8154b5a13371979d15000d6083626b1689f
Latest deploy log https://app.netlify.com/sites/lula-docs/deploys/65d5255b84952a0008e3e386

netlify[bot] avatar Dec 15 '23 18:12 netlify[bot]

Changing back to draft while working through errors.

CloudBeard avatar Dec 19 '23 19:12 CloudBeard

Tried gomock/testify and could only do a mock situation, basically create how it should work/fail. If the commands change or their functionality then the mock would still pass but the command may not work the same anymore.

Closest to live I could get was to create a geter function for root cmd so it could be used when the cmd package is imported but without making the root command itself public.

Created a fatal wrapper function since the main issue I was running into is the app exits on message.Fatalf this way on the commands that we don't have direct access to their functions (lint, uuidgen, mostly commands straight from go-oscal but maybe some from the shared zarf libraries in the future) we can pass that to the fatal wrapper which checks if it is in test mode, if so use the LogWriter function already in message.go and add in the test Test Mode Error Encountered and the error (easier to look for the error in tests) or if test mode is false it continues as normal and just exits.

Did run into concurrency issues running the tests/subtests in parallel while using the message.LogWriter. Open to suggestions there, main goal was not to add too much complexity for a couple of test cases but could be worth investigating the logging portion more.

CloudBeard avatar Feb 21 '24 00:02 CloudBeard

Closing issue as https://github.com/defenseunicorns/lula/issues/450 will encompass the testing for this and more.

CloudBeard avatar Jul 26 '24 21:07 CloudBeard