Skip to content

Commit

Permalink
tariff/octopusenergy: fix parsing of tariff setting (#13799)
Browse files Browse the repository at this point in the history
  • Loading branch information
duckfullstop authored May 7, 2024
1 parent 72fbbd1 commit d9b3d46
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tariff/octopus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions tariff/octopus_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit d9b3d46

Please sign in to comment.