Creating your project
Step 0: Write your project. You begin by writing your function in Go with print debugging. Make a directory where you would like to create your Go project andcd to that directory. (Our directory is /home/me/Projects — this will be printed in the logs later.)
myapp.go with the following content:
go.mod file. Do that by:
Using our SDK functions
Recall that the basic SDK workflow is:- Include Go SDK in dependencies.
- Use SDK functions in your code.
- Run the Go instrumentor. The instrumentor can be used for:
- Assertion cataloging only,
- Both assertion cataloging and coverage instrumentation.
- Build your Go project.
- Deploy your build.
Step 1: Include Go SDK in dependencies
RunStep 2: Use SDK functions in your code
You wrote a function to multiply numbers by ten. What sorts of properties should it have? The output should always be even. You should also make sure you are testing a wide variety of inputs, such as both even and odd numbers. Modify the code. The modifications are individually explained below.- Lines 5-6 You imported the assert and random libraries.
-
You added two assertions to times10.
- Line 14 You assert that the result is even using an Always Assertion. This is a fairly conventional assertion.
- Line 12 You insert a Sometimes Assertion, or an assertion that something will happen at least once across the entire testing session. You assert that sometimes during testing, the function will be called with an odd argument. The two types of assertions complement one another: Always Assertions assert that the behavior is correct, whereas Sometimes Assertions assert that you are testing under wide enough conditions to surface any potential incorrect behavior. In this case, the output would trivially be even if you only passed it even inputs — you must ensure your properties are not being trivially satisfied!
- Lines 20-22 You use randomness to call the function with many random values (between 0 and 500). Previously, you called the function with hardcoded values but now you will pass the function random values and test that the output is always even. This approach is more powerful but makes Sometimes Assertions necessary — now you must test that you are passing the function odd values, whereas previously the tests were hardcoded so you were certain that you were passing it odd values.
-
You call the random package’s GetRandom function to draw a random number, and then pass this random number to
times10. You use a loop to do this fifty times in a row. Every time the times10 function is called in this loop, it triggers the assertions in lines 12 & 14. -
In summary: You’ll test
times10by passing it a random integer fifty times in a row. You’ve asserted that all fifty outputs must be even and that at least one random input must be odd.
Step 3: Run the Go instrumentor with assertion cataloging and coverage instrumentation
When generating coverage instrumentation, the Go instrumentor will write the instrumented code to a target directory. (Nothing in your local directory will be modified.) The target directory must be an existing but empty directory. Create such a directory at the same level asmyapp:
Step 4: Build
Build your project.Ensure that you run the Go instrumentor before you compile your Go code. You must rerun the Go instrumentor every time you add new assertions, so that the new assertions will be cataloged.If you wanted to disable assertions, you could instead use the build tag
no_antithesis_sdk.E.g. go build -tags no_antithesis_sdkStep 5: Deploy your project
You’re now ready to build your project. If you’re building for local deployment then you’d be done here, but suppose instead you intend to send your project to Antithesis for testing. Antithesis will explore your software and search for violations of the properties you’ve defined. You must send us containers as described in getting started.- The executable should be included in your container. In this example,
myapp_generated_instrumentation/customer/myorg.myapp. - The instrumentation symbols (ending in
.sym.tsv) should be symlinked (or moved) into a directory named/symbolsin the root of the appropriate container image. The symbols must have the exact filename that is output by the instrumentor. In this example, if running the instrumentor produces the filego-182b876ae1ad.sym.tsv, then the resulting file should be copied to/symbols/go-182b876ae1ad.sym.tsv.
This example is simplified compared to what the full quickstart guide describes. Note that the function
main is the workload and times10 is the software itself. There are no dependencies. The instrumentation symbols will go in the configuration image as stated.