A small educational project with API tests in Go for Mars Rover Photos by NASA Open APIs.
This project demonstrates how to build and test a simple HTTP client in Go. It interacts with the NASA Mars Rover Photos API to fetch images taken by the rover Curiosity.
It includes:
- Real API integration
- Struct-based JSON decoding
- Table-driven integration tests
- Mock tests
- Positive and negative tests
- Logging with slog
- Allure reports
- GitHub Actions workflow for CI (automated testing)
- Linter golangci-lint
- Docker support
mars-go-tests/
├── .github/ # GitHub Actions
│ ├── workflows/ # CI/CD workflows
├── internal/
│ ├── api/ # easy HTTP Client
│ ├── config/ # Configuration loading
│ ├── constants/ # Base URL
│ ├── log/ # Logger
│ ├── models/ # Structs matching NASA's JSON format
├── test/ # Integration tests using real API, mock-tests, test data, test utils
├── go.mod / go.sum
├── .golangci.yml # Linter configuration
├── Dockerfile # Dockerfile for building and running the app
└── README.md
git clone https://github.com/your-username/mars-go-tests.git
cd mars-go-tests
Register at https://api.nasa.gov
You'll get a free API key by email
Create a file at internal/config/config.json with your API key:
{
"api_key": "your_actual_nasa_api_key_here"
}
Important: This file is ignored by Git. Do not commit your API key.
go test ./...
You'll see real-time responses from NASA's Open API being tested.
The report includes detailed information about the tests, with various attachments such as:
- Response JSON
- URLs of the mars rover's photos
- The first photo from the list
If running locally, to check the Allure Report, enter on the command line:
cd test
cd go test ./...
allure serve allure-results # This command will generate the report only when run from the 'test' directory
To run the project in a Docker container, follow these steps:
docker build -t mars-go-tests .
for Windows
docker run --rm -it -v %cd%/test/allure-report:/app/test/allure-report mars-go-tests
for Linux/macOS
docker run --rm -it -v $(pwd)/test/allure-report:/app/test/allure-report mars-go-tests
If you have Allure CLI installed, you can open the allure report from the command line.
allure open ./test/allure-report
If not, you can view the report by opening the file .test/allure-report/index.html in any browser.
The project uses GitHub Actions for continuous integration. The workflow file is located in .github/workflows/. It includes the following steps:
- Set up Go environment
- Cache Go modules for faster builds
- Install Allure dependencies and generate test reports
- Run tests and lint checks
The workflow triggers automatically on push to the main branch. You can view the build history and results on the GitHub Actions page. Additionally, you can download the generated Allure report as an artifact from the build results.
- Testify for assertions
- Allure-go for test reporting
- golangci-lint for linting
- Standard Go modules (
go.mod
,go.sum
)
MIT — feel free to use for educational purposes.
Maintained by @slazarska