From 0aff97edd0dc17ab74955f92af48df7d7ccefc01 Mon Sep 17 00:00:00 2001 From: Andrea Giacobino Date: Mon, 24 Jun 2024 01:57:07 +0200 Subject: [PATCH] test: download database before running tests the goals is to avoid having to commit the database blob --- Makefile | 3 ++- cmd/update.go | 17 ++++++++++++++--- coverage.out | 42 ------------------------------------------ db/rtree.go | 11 +++++------ 4 files changed, 21 insertions(+), 52 deletions(-) delete mode 100644 coverage.out diff --git a/Makefile b/Makefile index 2b3dce5..03c98b1 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,7 @@ test-coverage: go tool cover -html=coverage.out test-ci: + go run main.go update current go test -coverprofile=coverage.txt -covermode=atomic -race -mod=readonly $(GOPACKAGES) bench: bench-all @@ -68,5 +69,5 @@ update-tzdata: @echo "--> Updating timzaone data" @echo build binary goreleaser build --single-target --config .github/.goreleaser.yaml --snapshot --clean -o geo2tz - ./geo2tz update + ./geo2tz update latest @echo done diff --git a/cmd/update.go b/cmd/update.go index f707f43..94698b2 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -37,10 +37,13 @@ const ( var updateCmd = &cobra.Command{ Use: "update VERSION", Short: "Download the timezone data from the latest release or a specific version", - Example: `To build from the latest version: + Example: `To update using the tzdata/version.json file: +geo2tz update current + +To update to the latest version: geo2tz update latest -To build from a specific version: +To update to a specific version: geo2tz update 2023d `, Args: cobra.ExactArgs(1), @@ -65,10 +68,18 @@ func update(versionName, targetFile string) (err error) { return } } + // shall we read from the version file? + if versionName == "current" { + err = helpers.LoadJSON(web.Settings.Tz.VersionFile, &release) + if err != nil { + return + } + println("Current version is", release.Version) + } if err := fetchAndCacheFile(targetFile, release.GeoDataURL); err != nil { return err } - helpers.SaveJSON(release, web.Settings.Tz.VersionFile) + err = helpers.SaveJSON(release, web.Settings.Tz.VersionFile) return } diff --git a/coverage.out b/coverage.out deleted file mode 100644 index 2a6a6ca..0000000 --- a/coverage.out +++ /dev/null @@ -1,42 +0,0 @@ -mode: atomic -github.com/noandrea/geo2tz/v2/web/config.go:39.17,47.2 5 0 -github.com/noandrea/geo2tz/v2/web/config.go:50.46,53.2 1 0 -github.com/noandrea/geo2tz/v2/web/server.go:30.39,33.2 2 7 -github.com/noandrea/geo2tz/v2/web/server.go:36.62,38.2 1 2 -github.com/noandrea/geo2tz/v2/web/server.go:49.37,51.2 1 0 -github.com/noandrea/geo2tz/v2/web/server.go:53.46,57.24 4 0 -github.com/noandrea/geo2tz/v2/web/server.go:57.24,59.3 1 0 -github.com/noandrea/geo2tz/v2/web/server.go:60.2,60.8 1 0 -github.com/noandrea/geo2tz/v2/web/server.go:63.54,69.16 5 4 -github.com/noandrea/geo2tz/v2/web/server.go:69.16,72.3 2 1 -github.com/noandrea/geo2tz/v2/web/server.go:73.2,75.43 2 3 -github.com/noandrea/geo2tz/v2/web/server.go:75.43,78.3 2 0 -github.com/noandrea/geo2tz/v2/web/server.go:81.2,82.40 2 3 -github.com/noandrea/geo2tz/v2/web/server.go:82.40,85.3 2 0 -github.com/noandrea/geo2tz/v2/web/server.go:85.8,87.3 1 3 -github.com/noandrea/geo2tz/v2/web/server.go:89.2,96.16 6 3 -github.com/noandrea/geo2tz/v2/web/server.go:96.16,99.3 2 1 -github.com/noandrea/geo2tz/v2/web/server.go:100.2,101.68 2 2 -github.com/noandrea/geo2tz/v2/web/server.go:101.68,104.3 2 0 -github.com/noandrea/geo2tz/v2/web/server.go:107.2,110.21 3 2 -github.com/noandrea/geo2tz/v2/web/server.go:113.61,115.24 1 4 -github.com/noandrea/geo2tz/v2/web/server.go:115.24,117.50 2 0 -github.com/noandrea/geo2tz/v2/web/server.go:117.50,120.4 2 0 -github.com/noandrea/geo2tz/v2/web/server.go:123.2,124.16 2 4 -github.com/noandrea/geo2tz/v2/web/server.go:124.16,127.3 2 2 -github.com/noandrea/geo2tz/v2/web/server.go:129.2,130.16 2 2 -github.com/noandrea/geo2tz/v2/web/server.go:130.16,133.3 2 1 -github.com/noandrea/geo2tz/v2/web/server.go:136.2,137.16 2 1 -github.com/noandrea/geo2tz/v2/web/server.go:137.16,140.3 2 0 -github.com/noandrea/geo2tz/v2/web/server.go:141.2,141.97 1 1 -github.com/noandrea/geo2tz/v2/web/server.go:144.61,146.2 1 1 -github.com/noandrea/geo2tz/v2/web/server.go:149.57,150.34 1 19 -github.com/noandrea/geo2tz/v2/web/server.go:150.34,152.3 1 2 -github.com/noandrea/geo2tz/v2/web/server.go:153.2,154.16 2 17 -github.com/noandrea/geo2tz/v2/web/server.go:154.16,156.3 1 2 -github.com/noandrea/geo2tz/v2/web/server.go:157.2,157.14 1 15 -github.com/noandrea/geo2tz/v2/web/server.go:158.16,159.24 1 8 -github.com/noandrea/geo2tz/v2/web/server.go:159.24,161.4 1 4 -github.com/noandrea/geo2tz/v2/web/server.go:162.17,163.26 1 7 -github.com/noandrea/geo2tz/v2/web/server.go:163.26,165.4 1 4 -github.com/noandrea/geo2tz/v2/web/server.go:167.2,167.15 1 7 diff --git a/db/rtree.go b/db/rtree.go index 1911b14..5be4e70 100644 --- a/db/rtree.go +++ b/db/rtree.go @@ -79,9 +79,8 @@ func NewGeo2TzRTreeIndexFromGeoJSON(geoJSONPath string) (*Geo2TzRTreeIndex, erro // Lookup returns the timezone ID for a given latitude and longitude // if the timezone is not found, it returns an error // It first searches in the land index, if not found, it searches in the sea index -func (g *Geo2TzRTreeIndex) Lookup(lat, lng float64) (string, error) { +func (g *Geo2TzRTreeIndex) Lookup(lat, lng float64) (tzID string, err error) { - var tzID string g.land.Search( [2]float64{lat, lng}, [2]float64{lat, lng}, @@ -91,7 +90,7 @@ func (g *Geo2TzRTreeIndex) Lookup(lat, lng float64) (string, error) { }, ) - if len(tzID) == 0 { + if tzID == "" { g.sea.Search( [2]float64{lat, lng}, [2]float64{lat, lng}, @@ -102,10 +101,10 @@ func (g *Geo2TzRTreeIndex) Lookup(lat, lng float64) (string, error) { ) } - if len(tzID) == 0 { - return "", ErrNotFound + if tzID == "" { + err = ErrNotFound } - return tzID, nil + return } func (g *Geo2TzRTreeIndex) Size() int {