Add comprehensive test suite and documentation
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
- Complete unit, integration, and E2E test coverage (189 test cases) - Enhanced CI/CD pipeline with race detection and quality checks - Comprehensive godoc documentation for all packages - Updated README with API docs, examples, and deployment guides
This commit is contained in:
53
testdata/test_helper.go
vendored
Normal file
53
testdata/test_helper.go
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
package testdata
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestDBPath returns the path to test database files
|
||||
func TestDBPath() string {
|
||||
return filepath.Join("testdata")
|
||||
}
|
||||
|
||||
// CreateTempTestDB creates a temporary test database file
|
||||
func CreateTempTestDB(t *testing.T, filename string) string {
|
||||
t.Helper()
|
||||
|
||||
tempDir := t.TempDir()
|
||||
dbPath := filepath.Join(tempDir, filename)
|
||||
|
||||
// Create a minimal valid MMDB file header (this is just for testing file operations)
|
||||
// In real tests, we'd use actual MaxMind test database files
|
||||
content := []byte{
|
||||
0xab, 0xcd, 0xef, // Magic bytes for MaxMind DB format
|
||||
0x01, 0x00, 0x00, 0x00, // Version
|
||||
}
|
||||
|
||||
err := os.WriteFile(dbPath, content, 0644)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create test database: %v", err)
|
||||
}
|
||||
|
||||
return tempDir
|
||||
}
|
||||
|
||||
// TestIPs contains test IP addresses and their expected countries
|
||||
var TestIPs = map[string]string{
|
||||
"8.8.8.8": "US", // Google DNS
|
||||
"1.1.1.1": "US", // Cloudflare DNS
|
||||
"199.43.0.43": "US", // Test IP used in health check
|
||||
"127.0.0.1": "", // Localhost - should handle gracefully
|
||||
"192.168.1.1": "", // Private IP - should handle gracefully
|
||||
"2001:4860:4860::8888": "US", // Google IPv6 DNS
|
||||
}
|
||||
|
||||
// InvalidIPs contains invalid IP addresses for testing error handling
|
||||
var InvalidIPs = []string{
|
||||
"",
|
||||
"invalid",
|
||||
"256.256.256.256",
|
||||
"1.2.3",
|
||||
"not.an.ip",
|
||||
}
|
Reference in New Issue
Block a user