go-openweather/query_test.go

65 lines
1.3 KiB
Go
Raw Permalink Normal View History

2019-12-09 14:09:21 +00:00
package openweather
import (
"testing"
2020-01-22 14:50:41 +00:00
"github.com/EricNeid/go-openweather/internal/verify"
2019-12-09 14:09:21 +00:00
)
func TestNewQueryForCity(t *testing.T) {
// arrange
apiKey := "testKey"
2020-07-17 07:18:32 +00:00
location := "Berlin,de"
2019-12-09 14:09:21 +00:00
// action
q := NewQueryForCity(apiKey, location)
// verify
2020-01-22 14:40:23 +00:00
verify.Equals(t, apiKey, q.APIKey)
verify.Equals(t, location, q.Query)
verify.Equals(t, "metric", q.Unit)
verify.Equals(t, queryTypeCity, q.queryType)
2019-12-09 14:09:21 +00:00
// arrange
unit := "imperial"
// action
q = NewQueryForCity(apiKey, location, unit)
// verify
2020-01-22 14:40:23 +00:00
verify.Equals(t, unit, q.Unit)
2019-12-09 14:09:21 +00:00
}
func TestNewQueryForZip(t *testing.T) {
// arrange
apiKey := "testKey"
zip := "12345"
// action
q := NewQueryForZip(apiKey, zip)
// verify
2020-01-22 14:40:23 +00:00
verify.Equals(t, apiKey, q.APIKey)
verify.Equals(t, zip, q.Query)
verify.Equals(t, queryTypeZip, q.queryType)
2019-12-09 14:09:21 +00:00
}
func TestNewQueryForID(t *testing.T) {
// arrange
apiKey := "testKey"
id := "42"
// action
q := NewQueryForID(apiKey, id)
// verify
2020-01-22 14:40:23 +00:00
verify.Equals(t, apiKey, q.APIKey)
verify.Equals(t, id, q.Query)
verify.Equals(t, queryTypeID, q.queryType)
2019-12-09 14:09:21 +00:00
}
func TestNewQueryForLocation(t *testing.T) {
// arrange
apiKey := "testKey"
lat := "51"
lon := "13"
// action
q := NewQueryForLocation(apiKey, lat, lon)
// verify
2020-01-22 14:40:23 +00:00
verify.Equals(t, apiKey, q.APIKey)
verify.Equals(t, lat+"|"+lon, q.Query)
verify.Equals(t, queryTypeGeo, q.queryType)
2019-12-09 14:09:21 +00:00
}