tariff/octopusenergy: fix parsing of tariff setting (#13799)
This commit is contained in:
parent
72fbbd1bdb
commit
d9b3d46633
2 changed files with 35 additions and 1 deletions
|
|
@ -48,7 +48,7 @@ func NewOctopusFromConfig(other map[string]interface{}) (api.Tariff, error) {
|
|||
if cc.Region == "" {
|
||||
return nil, errors.New("missing region")
|
||||
}
|
||||
if cc.Tariff == "" {
|
||||
if cc.Tariff != "" {
|
||||
// deprecated - copy to correct slot and WARN
|
||||
logger.WARN.Print("'tariff' is deprecated and will break in a future version - use 'productCode' instead")
|
||||
cc.ProductCode = cc.Tariff
|
||||
|
|
|
|||
34
tariff/octopus_test.go
Normal file
34
tariff/octopus_test.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package tariff
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestOctopusConfigParse(t *testing.T) {
|
||||
// This test will start failing if you remove the deprecated "tariff" config var.
|
||||
validTariffConfig := map[string]interface{}{
|
||||
"region": "H",
|
||||
"tariff": "GO-22-03-29",
|
||||
}
|
||||
|
||||
_, err := NewOctopusFromConfig(validTariffConfig)
|
||||
require.NoError(t, err)
|
||||
|
||||
validProductCodeConfig := map[string]interface{}{
|
||||
"region": "H",
|
||||
"productcode": "GO-22-03-29",
|
||||
}
|
||||
|
||||
_, err = NewOctopusFromConfig(validProductCodeConfig)
|
||||
require.NoError(t, err)
|
||||
|
||||
invalidApiAndProductCodeConfig := map[string]interface{}{
|
||||
"region": "H",
|
||||
"productcode": "GO-22-03-29",
|
||||
"apikey": "nope",
|
||||
}
|
||||
_, err = NewOctopusFromConfig(invalidApiAndProductCodeConfig)
|
||||
require.Error(t, err)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue