Add lang parameter to OpenWeathermap input plugin (#6504)
This commit is contained in:
@@ -283,6 +283,7 @@ func TestForecastGeneratesMetrics(t *testing.T) {
|
||||
Fetch: []string{"weather", "forecast"},
|
||||
Units: "metric",
|
||||
}
|
||||
n.Init()
|
||||
|
||||
var acc testutil.Accumulator
|
||||
|
||||
@@ -293,38 +294,46 @@ func TestForecastGeneratesMetrics(t *testing.T) {
|
||||
testutil.MustMetric(
|
||||
"weather",
|
||||
map[string]string{
|
||||
"city_id": "2988507",
|
||||
"forecast": "3h",
|
||||
"city": "Paris",
|
||||
"country": "FR",
|
||||
"city_id": "2988507",
|
||||
"forecast": "3h",
|
||||
"city": "Paris",
|
||||
"country": "FR",
|
||||
"condition_id": "500",
|
||||
"condition_main": "Rain",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"cloudiness": int64(88),
|
||||
"humidity": int64(91),
|
||||
"pressure": 1018.65,
|
||||
"temperature": 6.71,
|
||||
"rain": 0.035,
|
||||
"wind_degrees": 228.501,
|
||||
"wind_speed": 3.76,
|
||||
"cloudiness": int64(88),
|
||||
"humidity": int64(91),
|
||||
"pressure": 1018.65,
|
||||
"temperature": 6.71,
|
||||
"rain": 0.035,
|
||||
"wind_degrees": 228.501,
|
||||
"wind_speed": 3.76,
|
||||
"condition_description": "light rain",
|
||||
"condition_icon": "10n",
|
||||
},
|
||||
time.Unix(1543622400, 0),
|
||||
),
|
||||
testutil.MustMetric(
|
||||
"weather",
|
||||
map[string]string{
|
||||
"city_id": "2988507",
|
||||
"forecast": "6h",
|
||||
"city": "Paris",
|
||||
"country": "FR",
|
||||
"city_id": "2988507",
|
||||
"forecast": "6h",
|
||||
"city": "Paris",
|
||||
"country": "FR",
|
||||
"condition_id": "500",
|
||||
"condition_main": "Rain",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"cloudiness": int64(92),
|
||||
"humidity": int64(98),
|
||||
"pressure": 1032.18,
|
||||
"temperature": 6.38,
|
||||
"rain": 0.049999999999997,
|
||||
"wind_degrees": 335.005,
|
||||
"wind_speed": 2.66,
|
||||
"cloudiness": int64(92),
|
||||
"humidity": int64(98),
|
||||
"pressure": 1032.18,
|
||||
"temperature": 6.38,
|
||||
"rain": 0.049999999999997,
|
||||
"wind_degrees": 335.005,
|
||||
"wind_speed": 2.66,
|
||||
"condition_description": "light rain",
|
||||
"condition_icon": "10n",
|
||||
},
|
||||
time.Unix(1544043600, 0),
|
||||
),
|
||||
@@ -358,6 +367,7 @@ func TestWeatherGeneratesMetrics(t *testing.T) {
|
||||
Fetch: []string{"weather"},
|
||||
Units: "metric",
|
||||
}
|
||||
n.Init()
|
||||
|
||||
var acc testutil.Accumulator
|
||||
|
||||
@@ -368,22 +378,26 @@ func TestWeatherGeneratesMetrics(t *testing.T) {
|
||||
testutil.MustMetric(
|
||||
"weather",
|
||||
map[string]string{
|
||||
"city_id": "2988507",
|
||||
"forecast": "*",
|
||||
"city": "Paris",
|
||||
"country": "FR",
|
||||
"city_id": "2988507",
|
||||
"forecast": "*",
|
||||
"city": "Paris",
|
||||
"country": "FR",
|
||||
"condition_id": "300",
|
||||
"condition_main": "Drizzle",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"cloudiness": int64(0),
|
||||
"humidity": int64(87),
|
||||
"pressure": 1007.0,
|
||||
"temperature": 9.25,
|
||||
"rain": 0.0,
|
||||
"sunrise": int64(1544167818000000000),
|
||||
"sunset": int64(1544198047000000000),
|
||||
"wind_degrees": 290.0,
|
||||
"wind_speed": 8.7,
|
||||
"visibility": 10000,
|
||||
"cloudiness": int64(0),
|
||||
"humidity": int64(87),
|
||||
"pressure": 1007.0,
|
||||
"temperature": 9.25,
|
||||
"rain": 0.0,
|
||||
"sunrise": int64(1544167818000000000),
|
||||
"sunset": int64(1544198047000000000),
|
||||
"wind_degrees": 290.0,
|
||||
"wind_speed": 8.7,
|
||||
"visibility": 10000,
|
||||
"condition_description": "light intensity drizzle",
|
||||
"condition_icon": "09d",
|
||||
},
|
||||
time.Unix(1544194800, 0),
|
||||
),
|
||||
@@ -414,6 +428,7 @@ func TestBatchWeatherGeneratesMetrics(t *testing.T) {
|
||||
Fetch: []string{"weather"},
|
||||
Units: "metric",
|
||||
}
|
||||
n.Init()
|
||||
|
||||
var acc testutil.Accumulator
|
||||
|
||||
@@ -424,66 +439,78 @@ func TestBatchWeatherGeneratesMetrics(t *testing.T) {
|
||||
testutil.MustMetric(
|
||||
"weather",
|
||||
map[string]string{
|
||||
"city_id": "524901",
|
||||
"forecast": "*",
|
||||
"city": "Moscow",
|
||||
"country": "RU",
|
||||
"city_id": "524901",
|
||||
"forecast": "*",
|
||||
"city": "Moscow",
|
||||
"country": "RU",
|
||||
"condition_id": "802",
|
||||
"condition_main": "Clouds",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"cloudiness": 40,
|
||||
"humidity": int64(46),
|
||||
"pressure": 1014.0,
|
||||
"temperature": 9.57,
|
||||
"wind_degrees": 60.0,
|
||||
"wind_speed": 5.0,
|
||||
"rain": 0.0,
|
||||
"sunrise": int64(1556416455000000000),
|
||||
"sunset": int64(1556470779000000000),
|
||||
"visibility": 10000,
|
||||
"cloudiness": 40,
|
||||
"humidity": int64(46),
|
||||
"pressure": 1014.0,
|
||||
"temperature": 9.57,
|
||||
"wind_degrees": 60.0,
|
||||
"wind_speed": 5.0,
|
||||
"rain": 0.0,
|
||||
"sunrise": int64(1556416455000000000),
|
||||
"sunset": int64(1556470779000000000),
|
||||
"visibility": 10000,
|
||||
"condition_description": "scattered clouds",
|
||||
"condition_icon": "03d",
|
||||
},
|
||||
time.Unix(1556444155, 0),
|
||||
),
|
||||
testutil.MustMetric(
|
||||
"weather",
|
||||
map[string]string{
|
||||
"city_id": "703448",
|
||||
"forecast": "*",
|
||||
"city": "Kiev",
|
||||
"country": "UA",
|
||||
"city_id": "703448",
|
||||
"forecast": "*",
|
||||
"city": "Kiev",
|
||||
"country": "UA",
|
||||
"condition_id": "520",
|
||||
"condition_main": "Rain",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"cloudiness": 0,
|
||||
"humidity": int64(63),
|
||||
"pressure": 1009.0,
|
||||
"temperature": 19.29,
|
||||
"wind_degrees": 0.0,
|
||||
"wind_speed": 1.0,
|
||||
"rain": 0.0,
|
||||
"sunrise": int64(1556419155000000000),
|
||||
"sunset": int64(1556471486000000000),
|
||||
"visibility": 10000,
|
||||
"cloudiness": 0,
|
||||
"humidity": int64(63),
|
||||
"pressure": 1009.0,
|
||||
"temperature": 19.29,
|
||||
"wind_degrees": 0.0,
|
||||
"wind_speed": 1.0,
|
||||
"rain": 0.0,
|
||||
"sunrise": int64(1556419155000000000),
|
||||
"sunset": int64(1556471486000000000),
|
||||
"visibility": 10000,
|
||||
"condition_description": "light intensity shower rain",
|
||||
"condition_icon": "09d",
|
||||
},
|
||||
time.Unix(1556444155, 0),
|
||||
),
|
||||
testutil.MustMetric(
|
||||
"weather",
|
||||
map[string]string{
|
||||
"city_id": "2643743",
|
||||
"forecast": "*",
|
||||
"city": "London",
|
||||
"country": "GB",
|
||||
"city_id": "2643743",
|
||||
"forecast": "*",
|
||||
"city": "London",
|
||||
"country": "GB",
|
||||
"condition_id": "803",
|
||||
"condition_main": "Clouds",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"cloudiness": 75,
|
||||
"humidity": int64(66),
|
||||
"pressure": 1019.0,
|
||||
"temperature": 10.62,
|
||||
"wind_degrees": 290.0,
|
||||
"wind_speed": 6.2,
|
||||
"rain": 0.072,
|
||||
"sunrise": int64(1556426319000000000),
|
||||
"sunset": int64(1556479032000000000),
|
||||
"visibility": 10000,
|
||||
"cloudiness": 75,
|
||||
"humidity": int64(66),
|
||||
"pressure": 1019.0,
|
||||
"temperature": 10.62,
|
||||
"wind_degrees": 290.0,
|
||||
"wind_speed": 6.2,
|
||||
"rain": 0.072,
|
||||
"sunrise": int64(1556426319000000000),
|
||||
"sunset": int64(1556479032000000000),
|
||||
"visibility": 10000,
|
||||
"condition_description": "broken clouds",
|
||||
"condition_icon": "04d",
|
||||
},
|
||||
time.Unix(1556444155, 0),
|
||||
),
|
||||
@@ -492,3 +519,31 @@ func TestBatchWeatherGeneratesMetrics(t *testing.T) {
|
||||
expected, acc.GetTelegrafMetrics(),
|
||||
testutil.SortMetrics())
|
||||
}
|
||||
|
||||
func TestFormatURL(t *testing.T) {
|
||||
n := &OpenWeatherMap{
|
||||
AppId: "appid",
|
||||
Units: "units",
|
||||
Lang: "lang",
|
||||
BaseUrl: "http://foo.com",
|
||||
}
|
||||
n.Init()
|
||||
|
||||
require.Equal(t,
|
||||
"http://foo.com/data/2.5/forecast?APPID=appid&id=12345&lang=lang&units=units",
|
||||
n.formatURL("/data/2.5/forecast", "12345"))
|
||||
}
|
||||
|
||||
func TestDefaultUnits(t *testing.T) {
|
||||
n := &OpenWeatherMap{}
|
||||
n.Init()
|
||||
|
||||
require.Equal(t, "metric", n.Units)
|
||||
}
|
||||
|
||||
func TestDefaultLang(t *testing.T) {
|
||||
n := &OpenWeatherMap{}
|
||||
n.Init()
|
||||
|
||||
require.Equal(t, "en", n.Lang)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user