git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/mmdb/verifier_test.go (about) 1 package mmdb 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestVerifyOnGoodDatabases(t *testing.T) { 11 databases := []string{ 12 "GeoIP2-Anonymous-IP-Test.mmdb", 13 "GeoIP2-City-Test.mmdb", 14 "GeoIP2-Connection-Type-Test.mmdb", 15 "GeoIP2-Country-Test.mmdb", 16 "GeoIP2-Domain-Test.mmdb", 17 "GeoIP2-ISP-Test.mmdb", 18 "GeoIP2-Precision-Enterprise-Test.mmdb", 19 "MaxMind-DB-no-ipv4-search-tree.mmdb", 20 "MaxMind-DB-string-value-entries.mmdb", 21 "MaxMind-DB-test-decoder.mmdb", 22 "MaxMind-DB-test-ipv4-24.mmdb", 23 "MaxMind-DB-test-ipv4-28.mmdb", 24 "MaxMind-DB-test-ipv4-32.mmdb", 25 "MaxMind-DB-test-ipv6-24.mmdb", 26 "MaxMind-DB-test-ipv6-28.mmdb", 27 "MaxMind-DB-test-ipv6-32.mmdb", 28 "MaxMind-DB-test-mixed-24.mmdb", 29 "MaxMind-DB-test-mixed-28.mmdb", 30 "MaxMind-DB-test-mixed-32.mmdb", 31 "MaxMind-DB-test-nested.mmdb", 32 } 33 34 for _, database := range databases { 35 t.Run(database, func(t *testing.T) { 36 reader, err := Open(testFile(database)) 37 require.NoError(t, err) 38 39 assert.NoError( 40 t, 41 reader.Verify(), 42 "Received error (%v) when verifying %v", 43 err, 44 database, 45 ) 46 }) 47 } 48 } 49 50 func TestVerifyOnBrokenDatabases(t *testing.T) { 51 databases := []string{ 52 "GeoIP2-City-Test-Broken-Double-Format.mmdb", 53 "MaxMind-DB-test-broken-pointers-24.mmdb", 54 "MaxMind-DB-test-broken-search-tree-24.mmdb", 55 } 56 57 for _, database := range databases { 58 reader, err := Open(testFile(database)) 59 assert.Nil(t, err) 60 assert.NotNil(t, reader.Verify(), 61 "Did not receive expected error when verifying %v", database, 62 ) 63 } 64 }