Testing and Debugging
Unit Tests
Purpose: The unit tests verify the functionality of individual components of the project.
Location: The unit tests are located in the
tests
directory. For example, tests for thedocker
command can be found intests/docker_test.go
.Execution:
- To run all unit tests:
go test ./...
- To run tests for a specific package:
go test ./tests/docker
- To run tests for a specific file:
go test ./tests/docker/docker_test.go
- To run all unit tests:
Example:
// docker_test.go package docker import ( "testing" ) func TestDockerRun(t *testing.T) { // ... test code ... }
Debugging
Tools:
- Go Debugger: The Go debugger (
dlv
) provides a powerful way to inspect the execution of your code. - Print Statements: Adding
fmt.Println
statements to your code can be a simple way to debug.
- Go Debugger: The Go debugger (
Example:
# Start a debugging session dlv debug ./main.go # Set a breakpoint at a specific line break main.go:15 # Continue execution continue # Inspect variables print variable
Debugging in Docker:
- Attach to a running container:
docker exec -it container-id bash
- Use
gdb
or other debuggers within the container.
- Attach to a running container:
Additional Resources
- Go Testing Documentation: https://go.dev/doc/tutorial/testing
- Go Debugger Documentation: https://github.com/go-delve/delve/
Note
- This information is based on the codebase of the provided project.
- The specific testing and debugging methods may vary depending on the project’s needs.
- Refer to the project’s documentation for more detailed information.