geoip_test.go 774 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (C) 2024 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package geoip
  7. import (
  8. "context"
  9. "net"
  10. "os"
  11. "strconv"
  12. "testing"
  13. )
  14. func TestDownloadAndOpen(t *testing.T) {
  15. acctID, _ := strconv.Atoi(os.Getenv("GEOIP_ACCOUNT_ID"))
  16. if acctID == 0 {
  17. t.Skip("No account ID set")
  18. }
  19. license := os.Getenv("GEOIP_LICENSE_KEY")
  20. if license == "" {
  21. t.Skip("No license key set")
  22. }
  23. p, err := NewGeoLite2CityProvider(context.Background(), acctID, license, t.TempDir())
  24. if err != nil {
  25. t.Fatal(err)
  26. }
  27. _, err = p.City(net.ParseIP("8.8.8.8"))
  28. if err != nil {
  29. t.Fatal(err)
  30. }
  31. }