go-openweather/integration_test.go

87 lines
1.8 KiB
Go

// +build integration
package openweather
import (
"io/ioutil"
"testing"
"github.com/EricNeid/go-openweather/internal/verify"
)
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
verify.Ok(t, err)
verify.Assert(t, len(resp) > 0, "Received empty response")
}
func TestWeatherRaw(t *testing.T) {
// arrange
q := NewQueryForCity(readAPIKey(), cityBerlin)
// action
resp, err := q.WeatherRaw()
// verify
verify.Ok(t, err)
verify.Assert(t, len(resp) > 0, "Received empty response")
}
func TestWeather(t *testing.T) {
// arrange
q := NewQueryForCity(readAPIKey(), cityBerlin)
// action
data, err := q.Weather()
// verify
verify.Ok(t, err)
verify.Equals(t, "Berlin", data.Name)
}
func TestDailyForecast(t *testing.T) {
// arrange
q := NewQueryForCity(readAPIKey(), cityBerlin)
// action
data, err := q.DailyForecast5()
// verify
verify.Ok(t, err)
verify.Equals(t, "Berlin", data.City.Name)
}
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")
}