summaryrefslogtreecommitdiffstats
path: root/photon/photon_test.go
blob: 3a87bc8cd74b1b412e2ebbfe0ef8d9db9b9cde79 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
	}
}