diff --git a/tariff/octopus.go b/tariff/octopus.go index 1a496573a..eb69484a7 100644 --- a/tariff/octopus.go +++ b/tariff/octopus.go @@ -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 diff --git a/tariff/octopus_test.go b/tariff/octopus_test.go new file mode 100644 index 000000000..30a4f5245 --- /dev/null +++ b/tariff/octopus_test.go @@ -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) +}