Skip to content

Commit

Permalink
test: download database before running tests
Browse files Browse the repository at this point in the history
the goals is to avoid having to commit the database blob
  • Loading branch information
noandrea committed Jun 24, 2024
1 parent 52468cf commit 70c5801
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 52 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
17 changes: 14 additions & 3 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
}

Expand Down
42 changes: 0 additions & 42 deletions coverage.out

This file was deleted.

11 changes: 5 additions & 6 deletions db/rtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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},
Expand All @@ -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 {
Expand Down

0 comments on commit 70c5801

Please sign in to comment.