mirror of
https://github.com/EricNeid/go-openweather.git
synced 2025-01-25 12:56:16 +00:00
Merge branch 'master' of github.com:EricNeid/go-openweather
This commit is contained in:
commit
6b94f9f617
37
.github/workflows/go.yml
vendored
Normal file
37
.github/workflows/go.yml
vendored
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
name: Go
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Set up Go 1.x
|
||||||
|
uses: actions/setup-go@v2
|
||||||
|
with:
|
||||||
|
go-version: ^1.13
|
||||||
|
id: go
|
||||||
|
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Get dependencies
|
||||||
|
run: |
|
||||||
|
go get -v -t -d ./...
|
||||||
|
if [ -f Gopkg.toml ]; then
|
||||||
|
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
|
||||||
|
dep ensure
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: go build -v .
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: go test -v .
|
2
.gitpod.yml
Normal file
2
.gitpod.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
tasks:
|
||||||
|
- init: go get && make build && make test
|
13
README.md
13
README.md
@ -1,9 +1,16 @@
|
|||||||
# go - openweatherapi
|
<!-- markdownlint-disable MD041-->
|
||||||
|
[![Go Report Card](https://goreportcard.com/badge/github.com/EricNeid/go-openweather?style=flat-square)](https://goreportcard.com/report/github.com/EricNeid/go-openweather)
|
||||||
|
![Go](https://github.com/EricNeid/go-openweather/workflows/Go/badge.svg)
|
||||||
|
[![Go Doc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](http://godoc.org/github.com/EricNeid/go-openweather)
|
||||||
|
[![Release](https://img.shields.io/github/release/EricNeid/go-openweather.svg?style=flat-square)](https://github.com/EricNeid/go-openweather/releases/latest)
|
||||||
|
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/EricNeid/go-openweather)
|
||||||
|
|
||||||
|
# About
|
||||||
|
|
||||||
This Repo contains golang library to query OpenWetherMaps (<http://openweathermap.org/>) for weather information.
|
This Repo contains golang library to query OpenWetherMaps (<http://openweathermap.org/>) for weather information.
|
||||||
|
|
||||||
* current weather: http://openweathermap.org/current
|
* current weather: <http://openweathermap.org/current>
|
||||||
* 5 days forecast: http://openweathermap.org/forecast5
|
* 5 days forecast: <http://openweathermap.org/forecast5>
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
|
// +build integration
|
||||||
|
|
||||||
package openweather
|
package openweather
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/EricNeid/go-openweather/internal/test"
|
"github.com/EricNeid/go-openweather/internal/verify"
|
||||||
)
|
)
|
||||||
|
|
||||||
const apiKeyFile = "testdata/api.key"
|
const apiKeyFile = "testdata/api.key"
|
||||||
@ -29,8 +31,8 @@ func TestForecastRaw(t *testing.T) {
|
|||||||
// action
|
// action
|
||||||
resp, err := q.DailyForecast5Raw()
|
resp, err := q.DailyForecast5Raw()
|
||||||
// verify
|
// verify
|
||||||
test.Ok(t, err)
|
verify.Ok(t, err)
|
||||||
test.Assert(t, len(resp) > 0, "Received empty response")
|
verify.Assert(t, len(resp) > 0, "Received empty response")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWeatherRaw(t *testing.T) {
|
func TestWeatherRaw(t *testing.T) {
|
||||||
@ -39,8 +41,8 @@ func TestWeatherRaw(t *testing.T) {
|
|||||||
// action
|
// action
|
||||||
resp, err := q.WeatherRaw()
|
resp, err := q.WeatherRaw()
|
||||||
// verify
|
// verify
|
||||||
test.Ok(t, err)
|
verify.Ok(t, err)
|
||||||
test.Assert(t, len(resp) > 0, "Received empty response")
|
verify.Assert(t, len(resp) > 0, "Received empty response")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWeather(t *testing.T) {
|
func TestWeather(t *testing.T) {
|
||||||
@ -49,8 +51,8 @@ func TestWeather(t *testing.T) {
|
|||||||
// action
|
// action
|
||||||
data, err := q.Weather()
|
data, err := q.Weather()
|
||||||
// verify
|
// verify
|
||||||
test.Ok(t, err)
|
verify.Ok(t, err)
|
||||||
test.Equals(t, "Berlin", data.Name)
|
verify.Equals(t, "Berlin", data.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDailyForecast(t *testing.T) {
|
func TestDailyForecast(t *testing.T) {
|
||||||
@ -59,8 +61,8 @@ func TestDailyForecast(t *testing.T) {
|
|||||||
// action
|
// action
|
||||||
data, err := q.DailyForecast5()
|
data, err := q.DailyForecast5()
|
||||||
// verify
|
// verify
|
||||||
test.Ok(t, err)
|
verify.Ok(t, err)
|
||||||
test.Equals(t, "Berlin", data.City.Name)
|
verify.Equals(t, "Berlin", data.City.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDailyForecast5(t *testing.T) {
|
func TestDailyForecast5(t *testing.T) {
|
@ -1,4 +1,4 @@
|
|||||||
package test
|
package verify
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -3,27 +3,27 @@ package openweather
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/EricNeid/go-openweather/internal/test"
|
"github.com/EricNeid/go-openweather/internal/verify"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewQueryForCity(t *testing.T) {
|
func TestNewQueryForCity(t *testing.T) {
|
||||||
// arrange
|
// arrange
|
||||||
apiKey := "testKey"
|
apiKey := "testKey"
|
||||||
location := cityBerlin
|
location := "Berlin,de"
|
||||||
// action
|
// action
|
||||||
q := NewQueryForCity(apiKey, location)
|
q := NewQueryForCity(apiKey, location)
|
||||||
// verify
|
// verify
|
||||||
test.Equals(t, apiKey, q.APIKey)
|
verify.Equals(t, apiKey, q.APIKey)
|
||||||
test.Equals(t, location, q.Query)
|
verify.Equals(t, location, q.Query)
|
||||||
test.Equals(t, "metric", q.Unit)
|
verify.Equals(t, "metric", q.Unit)
|
||||||
test.Equals(t, queryTypeCity, q.queryType)
|
verify.Equals(t, queryTypeCity, q.queryType)
|
||||||
|
|
||||||
// arrange
|
// arrange
|
||||||
unit := "imperial"
|
unit := "imperial"
|
||||||
// action
|
// action
|
||||||
q = NewQueryForCity(apiKey, location, unit)
|
q = NewQueryForCity(apiKey, location, unit)
|
||||||
// verify
|
// verify
|
||||||
test.Equals(t, unit, q.Unit)
|
verify.Equals(t, unit, q.Unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewQueryForZip(t *testing.T) {
|
func TestNewQueryForZip(t *testing.T) {
|
||||||
@ -33,9 +33,9 @@ func TestNewQueryForZip(t *testing.T) {
|
|||||||
// action
|
// action
|
||||||
q := NewQueryForZip(apiKey, zip)
|
q := NewQueryForZip(apiKey, zip)
|
||||||
// verify
|
// verify
|
||||||
test.Equals(t, apiKey, q.APIKey)
|
verify.Equals(t, apiKey, q.APIKey)
|
||||||
test.Equals(t, zip, q.Query)
|
verify.Equals(t, zip, q.Query)
|
||||||
test.Equals(t, queryTypeZip, q.queryType)
|
verify.Equals(t, queryTypeZip, q.queryType)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewQueryForID(t *testing.T) {
|
func TestNewQueryForID(t *testing.T) {
|
||||||
@ -45,9 +45,9 @@ func TestNewQueryForID(t *testing.T) {
|
|||||||
// action
|
// action
|
||||||
q := NewQueryForID(apiKey, id)
|
q := NewQueryForID(apiKey, id)
|
||||||
// verify
|
// verify
|
||||||
test.Equals(t, apiKey, q.APIKey)
|
verify.Equals(t, apiKey, q.APIKey)
|
||||||
test.Equals(t, id, q.Query)
|
verify.Equals(t, id, q.Query)
|
||||||
test.Equals(t, queryTypeID, q.queryType)
|
verify.Equals(t, queryTypeID, q.queryType)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewQueryForLocation(t *testing.T) {
|
func TestNewQueryForLocation(t *testing.T) {
|
||||||
@ -58,7 +58,7 @@ func TestNewQueryForLocation(t *testing.T) {
|
|||||||
// action
|
// action
|
||||||
q := NewQueryForLocation(apiKey, lat, lon)
|
q := NewQueryForLocation(apiKey, lat, lon)
|
||||||
// verify
|
// verify
|
||||||
test.Equals(t, apiKey, q.APIKey)
|
verify.Equals(t, apiKey, q.APIKey)
|
||||||
test.Equals(t, lat+"|"+lon, q.Query)
|
verify.Equals(t, lat+"|"+lon, q.Query)
|
||||||
test.Equals(t, queryTypeGeo, q.queryType)
|
verify.Equals(t, queryTypeGeo, q.queryType)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user