summaryrefslogtreecommitdiffstats
path: root/photon/photon_test.go
diff options
context:
space:
mode:
authorsiddharth ravikumar <s@ricketyspace.net>2022-05-28 03:59:57 -0400
committersiddharth ravikumar <s@ricketyspace.net>2022-05-28 03:59:57 -0400
commit5605f78daca7db0bb4c22d28a9286c01cc4da0da (patch)
tree127f215b187a9098ad79f38422829e6bc61b8fa4 /photon/photon_test.go
parent45a802e845f19c2934141df77e8ab82c21a41109 (diff)
peach: add photon package
Diffstat (limited to 'photon/photon_test.go')
-rw-r--r--photon/photon_test.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/photon/photon_test.go b/photon/photon_test.go
new file mode 100644
index 0000000..3a87bc8
--- /dev/null
+++ b/photon/photon_test.go
@@ -0,0 +1,67 @@
+// Copyright © 2022 siddharth ravikumar <s@ricketyspace.net>
+// SPDX-License-Identifier: ISC
+
+package photon
+
+import (
+ "os"
+ "testing"
+)
+
+func TestEnabled(t *testing.T) {
+ if Enabled() {
+ t.Errorf("geo is enabled")
+ return
+ }
+
+ os.Setenv("PEACH_PHOTON_URL", "https://photon.komoot.io")
+ if !Enabled() {
+ t.Errorf("geo is not enabled")
+ return
+ }
+}
+
+func TestPhotonUrl(t *testing.T) {
+ os.Setenv("PEACH_PHOTON_URL", "")
+ pUrl, err := Url()
+ if err == nil {
+ t.Errorf("url: %v", pUrl)
+ return
+ }
+
+ os.Setenv("PEACH_PHOTON_URL", "https://photon.komoot.io")
+ pUrl, err = Url()
+ if err != nil {
+ t.Errorf("url: %v", err)
+ return
+ }
+ if pUrl.String() != "https://photon.komoot.io/api" {
+ t.Errorf("url: %v", pUrl)
+ return
+ }
+}
+
+func TestGeocode(t *testing.T) {
+ os.Setenv("PEACH_PHOTON_URL", "https://photon.komoot.io")
+ mCoords, err := Geocode("Tiffin,OH")
+ if err != nil {
+ t.Errorf("%v", err)
+ return
+ }
+ if len(mCoords) < 0 {
+ t.Errorf("no matching coordinates")
+ return
+ }
+ if mCoords[0].Lat != 41.114485 {
+ t.Errorf("lat: %v", mCoords[0].Lat)
+ return
+ }
+ if mCoords[0].Lng != -83.1779537 {
+ t.Errorf("lng: %v", mCoords[0].Lat)
+ return
+ }
+ if mCoords[0].Name != "Tiffin, Ohio" {
+ t.Errorf("name: %v", mCoords[0].Name)
+ return
+ }
+}