mirror of
https://github.com/noandrea/geo2tz.git
synced 2025-12-22 10:47:07 +00:00
test: download database before running tests
the goals is to avoid having to commit the database blob
This commit is contained in:
3
Makefile
3
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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
42
coverage.out
42
coverage.out
@@ -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
|
||||
11
db/rtree.go
11
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 {
|
||||
|
||||
Reference in New Issue
Block a user