go-openweather/integration_test.go

87 lines
1.8 KiB
Go
Raw Normal View History

2020-07-17 07:18:32 +00:00
// +build integration
2019-12-09 14:09:21 +00:00
package openweather
import (
"io/ioutil"
"testing"
2020-01-22 14:50:41 +00:00
"github.com/EricNeid/go-openweather/internal/verify"
2019-12-09 14:09:21 +00:00
)
const apiKeyFile = "testdata/api.key"
const cityBerlin = "Berlin,de"
func readAPIKey() string {
key, err := ioutil.ReadFile(apiKeyFile)
if err != nil {
panic(`
Cannot run test, you must provide openweathermap api key.
Expected: testdata/api.key
See https://home.openweathermap.org/users/sign_up
for information how to obtain a key`)
}
return string(key)
}
func TestForecastRaw(t *testing.T) {
// arrange
q := NewQueryForCity(readAPIKey(), cityBerlin)
// action
resp, err := q.DailyForecast5Raw()
// verify
2020-01-22 14:40:23 +00:00
verify.Ok(t, err)
verify.Assert(t, len(resp) > 0, "Received empty response")
2019-12-09 14:09:21 +00:00
}
func TestWeatherRaw(t *testing.T) {
// arrange
q := NewQueryForCity(readAPIKey(), cityBerlin)
// action
resp, err := q.WeatherRaw()
// verify
2020-01-22 14:40:23 +00:00
verify.Ok(t, err)
verify.Assert(t, len(resp) > 0, "Received empty response")
2019-12-09 14:09:21 +00:00
}
func TestWeather(t *testing.T) {
// arrange
q := NewQueryForCity(readAPIKey(), cityBerlin)
// action
data, err := q.Weather()
// verify
2020-01-22 14:40:23 +00:00
verify.Ok(t, err)
verify.Equals(t, "Berlin", data.Name)
2019-12-09 14:09:21 +00:00
}
func TestDailyForecast(t *testing.T) {
// arrange
q := NewQueryForCity(readAPIKey(), cityBerlin)
// action
data, err := q.DailyForecast5()
// verify
2020-01-22 14:40:23 +00:00
verify.Ok(t, err)
verify.Equals(t, "Berlin", data.City.Name)
2019-12-09 14:09:21 +00:00
}
2020-11-06 07:38:14 +00:00
func TestDailyForecast5(t *testing.T) {
// arrange
q := NewQueryForCity(readAPIKey(), cityBerlin)
// action
data, err := q.DailyForecast5()
// verify
test.Ok(t, err)
test.Equals(t, "Berlin", data.City.Name)
}
func TestDailyForecast5Raw(t *testing.T) {
// arrange
q := NewQueryForCity(readAPIKey(), cityBerlin)
// action
data, err := q.DailyForecast5Raw()
// verify
test.Ok(t, err)
test.Assert(t, len(data) > 0, "Empty response received")
}