test: add unit test suite and run tests in CI - #27
Merged
Conversation
Add an httptest-based test suite for the web API client (scan upload, rescan, download, delete, search, listing, file status), tests for the util helpers, and tests for the scan summary / hash collection helpers in cmd. Extend the CI workflow to run go vet and go test -race in addition to the build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The project previously had zero tests, and CI only ran
go build. This PR adds the first test suite and wires it into CI.internal/webapi—httptest-based tests for the API client coveringScan(multipart form fields, auth header, filename, error paths),Rescan(request body),FileExists,GetFile,GetFileStatus,ListFiles(including API error messages),SearchFiles(including error paths),Download, andDelete. No network access needed.internal/util— tests for hashing, file read/write helpers,Exists/MkDir, slice helpers, and directory walking.cmd— tests for the pure helpers:buildScanSummary(including the nested MultiAV extraction) andcollectHashes/sha256Re.go vet ./...andgo test -race -v ./...on all three platforms in addition to the build.Tests intentionally cover current behavior only; known bugs found during review (unchecked HTTP status codes in
Rescan/Download/Delete, the short-read inutil.ReadAll, etc.) will be fixed in follow-up PRs with their own regression tests.Test plan
go build ./... && go vet ./... && go test -race ./...passes locally on linux.