|
|
1 vecka sedan | |
|---|---|---|
| .. | ||
| README.md | 1 vecka sedan | |
| beacons_test.go | 1 vecka sedan | |
| distance_test.go | 1 vecka sedan | |
| mqtthandler_test.go | 1 vecka sedan | |
| typeMethods_test.go | 1 vecka sedan | |
This directory contains comprehensive unit tests for the high-priority internal packages of the AFASystems presence detection system.
The following files have been thoroughly tested:
distance_test.go - Tests for distance calculation utilities
CalculateDistance() - Distance calculation from RSSI and TX powertwosComp() - Two’s complement hex conversionValidateRSSI() - RSSI value validationValidateTXPower() - TX power validationbeacons_test.go - Tests for beacon parsing utilities
ParseADFast() - Advertising Data structure parsingRemoveFlagBytes() - Bluetooth flag bytes removalLoopADStructures() - Beacon type detection and parsingisValidADStructure() - AD structure validationtypeMethods_test.go - Tests for model type methods
Hash() - Beacon event hash generation with battery roundingToJSON() - JSON marshaling for beacon eventsconvertStructToMap() - Generic struct-to-map conversionRedisHashable() - Redis hash map conversion for HTTPLocation and BeaconEventmqtthandler_test.go - Tests for MQTT message processing
MqttHandler() - Main MQTT message processing with JSON/CSV inputparseButtonState() - Button counter parsing for different beacon formatsgo test ./test/... -v
go test ./test/distance_test.go -v
go test ./test/beacons_test.go -v
go test ./test/typeMethods_test.go -v
go test ./test/mqtthandler_test.go -v
go test ./test/distance_test.go -run TestCalculateDistance -v
go test ./test/beacons_test.go -run TestParseADFast -v
go test ./test/typeMethods_test.go -run TestHash -v
go test ./test/mqtthandler_test.go -run TestMqttHandlerJSONArrayInput -v
# Run all benchmarks
go test ./test/... -bench=.
# Run specific benchmarks
go test ./test/distance_test.go -bench=BenchmarkCalculateDistance -v
go test ./test/beacons_test.go -bench=BenchmarkParseADFast -v
go test ./test/typeMethods_test.go -bench=BenchmarkHash -v
go test ./test/mqtthandler_test.go -bench=BenchmarkMqttHandlerJSON -v
go test ./test/... -cover
go test ./test/... -coverprofile=coverage.out
go tool cover -html=coverage.out -o coverage.html
go test ./test/... -race -v
Each test file follows Go testing conventions with:
The mqtthandler tests use a MockKafkaWriter to simulate Kafka operations without requiring a running Kafka instance. This allows for:
mqtthandler.go contains os.Exit(2) calls which make it untestable. The test demonstrates the intended structure but cannot fully validate CSV processing due to this design choice.These tests demonstrate several Go testing best practices:
For automated testing environments:
# Standard CI test run
go test ./test/... -race -cover -timeout=30s
# Performance regression testing
go test ./test/... -bench=. -benchmem
This comprehensive test suite ensures the reliability and correctness of the core business logic in the AFASystems presence detection system.