Chore: Replace yaml.v2 with yaml.v3 (#59897)
* replace yaml.v2 with yaml.v3 * fix a few tests due to the yaml.v3 api changes * and another goconvey mistake in tests
This commit is contained in:
@@ -121,7 +121,7 @@ require (
|
|||||||
gopkg.in/ldap.v3 v3.1.0
|
gopkg.in/ldap.v3 v3.1.0
|
||||||
gopkg.in/mail.v2 v2.3.1
|
gopkg.in/mail.v2 v2.3.1
|
||||||
gopkg.in/square/go-jose.v2 v2.5.1
|
gopkg.in/square/go-jose.v2 v2.5.1
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
xorm.io/builder v0.3.6
|
xorm.io/builder v0.3.6
|
||||||
xorm.io/core v0.7.3
|
xorm.io/core v0.7.3
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package featuremgmt
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type configBody struct {
|
type configBody struct {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import (
|
|||||||
"github.com/prometheus/alertmanager/notify"
|
"github.com/prometheus/alertmanager/notify"
|
||||||
"github.com/prometheus/alertmanager/types"
|
"github.com/prometheus/alertmanager/types"
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type rulesConfigReader struct {
|
type rulesConfigReader struct {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/services/provisioning/values"
|
"github.com/grafana/grafana/pkg/services/provisioning/values"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestReceivers(t *testing.T) {
|
func TestReceivers(t *testing.T) {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/provisioning/utils"
|
"github.com/grafana/grafana/pkg/services/provisioning/utils"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type configReader struct {
|
type configReader struct {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/services/datasources"
|
"github.com/grafana/grafana/pkg/services/datasources"
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/grafana/grafana/pkg/services/org"
|
"github.com/grafana/grafana/pkg/services/org"
|
||||||
"github.com/grafana/grafana/pkg/services/provisioning/utils"
|
"github.com/grafana/grafana/pkg/services/provisioning/utils"
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type configReader struct {
|
type configReader struct {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/plugins"
|
"github.com/grafana/grafana/pkg/plugins"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type configReader interface {
|
type configReader interface {
|
||||||
|
|||||||
@@ -210,8 +210,8 @@ func (val *JSONSliceValue) UnmarshalYAML(unmarshal func(interface{}) error) erro
|
|||||||
for _, v := range unmarshaled {
|
for _, v := range unmarshaled {
|
||||||
i := make(map[string]interface{})
|
i := make(map[string]interface{})
|
||||||
r := make(map[string]interface{})
|
r := make(map[string]interface{})
|
||||||
for key, val := range v.(map[interface{}]interface{}) {
|
for key, val := range v.(map[string]interface{}) {
|
||||||
i[key.(string)], r[key.(string)], err = transformInterface(val)
|
i[key], r[key], err = transformInterface(val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -245,7 +245,7 @@ func transformInterface(i interface{}) (interface{}, interface{}, error) {
|
|||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
return transformSlice(i.([]interface{}))
|
return transformSlice(i.([]interface{}))
|
||||||
case reflect.Map:
|
case reflect.Map:
|
||||||
return transformMap(i.(map[interface{}]interface{}))
|
return transformMap(i.(map[string]interface{}))
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
return interpolateValue(i.(string))
|
return interpolateValue(i.(string))
|
||||||
default:
|
default:
|
||||||
@@ -268,17 +268,14 @@ func transformSlice(i []interface{}) (interface{}, interface{}, error) {
|
|||||||
return transformedSlice, rawSlice, nil
|
return transformedSlice, rawSlice, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func transformMap(i map[interface{}]interface{}) (interface{}, interface{}, error) {
|
func transformMap(i map[string]interface{}) (interface{}, interface{}, error) {
|
||||||
transformed := make(map[string]interface{})
|
transformed := make(map[string]interface{})
|
||||||
raw := make(map[string]interface{})
|
raw := make(map[string]interface{})
|
||||||
for key, val := range i {
|
for key, val := range i {
|
||||||
stringKey, ok := key.(string)
|
var err error
|
||||||
if ok {
|
transformed[key], raw[key], err = transformInterface(val)
|
||||||
var err error
|
if err != nil {
|
||||||
transformed[stringKey], raw[stringKey], err = transformInterface(val)
|
return nil, nil, err
|
||||||
if err != nil {
|
|
||||||
return nil, nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return transformed, raw, nil
|
return transformed, raw, nil
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"gopkg.in/ini.v1"
|
"gopkg.in/ini.v1"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestValues(t *testing.T) {
|
func TestValues(t *testing.T) {
|
||||||
@@ -39,21 +39,23 @@ func TestValues(t *testing.T) {
|
|||||||
type Data struct {
|
type Data struct {
|
||||||
Val IntValue `yaml:"val"`
|
Val IntValue `yaml:"val"`
|
||||||
}
|
}
|
||||||
d := &Data{}
|
|
||||||
|
|
||||||
t.Run("Should unmarshal simple number", func(t *testing.T) {
|
t.Run("Should unmarshal simple number", func(t *testing.T) {
|
||||||
|
d := &Data{}
|
||||||
|
|
||||||
unmarshalingTest(t, `val: 1`, d)
|
unmarshalingTest(t, `val: 1`, d)
|
||||||
require.Equal(t, d.Val.Value(), 1)
|
require.Equal(t, d.Val.Value(), 1)
|
||||||
require.Equal(t, d.Val.Raw, "1")
|
require.Equal(t, d.Val.Raw, "1")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Should unmarshal env var", func(t *testing.T) {
|
t.Run("Should unmarshal env var", func(t *testing.T) {
|
||||||
|
d := &Data{}
|
||||||
unmarshalingTest(t, `val: $INT`, d)
|
unmarshalingTest(t, `val: $INT`, d)
|
||||||
require.Equal(t, d.Val.Value(), 1)
|
require.Equal(t, d.Val.Value(), 1)
|
||||||
require.Equal(t, d.Val.Raw, "$INT")
|
require.Equal(t, d.Val.Raw, "$INT")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Should ignore empty value", func(t *testing.T) {
|
t.Run("Should ignore empty value", func(t *testing.T) {
|
||||||
|
d := &Data{}
|
||||||
unmarshalingTest(t, `val: `, d)
|
unmarshalingTest(t, `val: `, d)
|
||||||
require.Equal(t, d.Val.Value(), 0)
|
require.Equal(t, d.Val.Value(), 0)
|
||||||
require.Equal(t, d.Val.Raw, "")
|
require.Equal(t, d.Val.Raw, "")
|
||||||
@@ -64,39 +66,43 @@ func TestValues(t *testing.T) {
|
|||||||
type Data struct {
|
type Data struct {
|
||||||
Val StringValue `yaml:"val"`
|
Val StringValue `yaml:"val"`
|
||||||
}
|
}
|
||||||
d := &Data{}
|
|
||||||
|
|
||||||
t.Run("Should unmarshal simple string", func(t *testing.T) {
|
t.Run("Should unmarshal simple string", func(t *testing.T) {
|
||||||
|
d := &Data{}
|
||||||
unmarshalingTest(t, `val: test`, d)
|
unmarshalingTest(t, `val: test`, d)
|
||||||
require.Equal(t, d.Val.Value(), "test")
|
require.Equal(t, d.Val.Value(), "test")
|
||||||
require.Equal(t, d.Val.Raw, "test")
|
require.Equal(t, d.Val.Raw, "test")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Should unmarshal env var", func(t *testing.T) {
|
t.Run("Should unmarshal env var", func(t *testing.T) {
|
||||||
|
d := &Data{}
|
||||||
unmarshalingTest(t, `val: $STRING`, d)
|
unmarshalingTest(t, `val: $STRING`, d)
|
||||||
require.Equal(t, d.Val.Value(), "test")
|
require.Equal(t, d.Val.Value(), "test")
|
||||||
require.Equal(t, d.Val.Raw, "$STRING")
|
require.Equal(t, d.Val.Raw, "$STRING")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Should ignore empty value", func(t *testing.T) {
|
t.Run("Should ignore empty value", func(t *testing.T) {
|
||||||
|
d := &Data{}
|
||||||
unmarshalingTest(t, `val: `, d)
|
unmarshalingTest(t, `val: `, d)
|
||||||
require.Equal(t, d.Val.Value(), "")
|
require.Equal(t, d.Val.Value(), "")
|
||||||
require.Equal(t, d.Val.Raw, "")
|
require.Equal(t, d.Val.Raw, "")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("empty var should have empty value", func(t *testing.T) {
|
t.Run("empty var should have empty value", func(t *testing.T) {
|
||||||
|
d := &Data{}
|
||||||
unmarshalingTest(t, `val: $EMPTYSTRING`, d)
|
unmarshalingTest(t, `val: $EMPTYSTRING`, d)
|
||||||
require.Equal(t, d.Val.Value(), "")
|
require.Equal(t, d.Val.Value(), "")
|
||||||
require.Equal(t, d.Val.Raw, "$EMPTYSTRING")
|
require.Equal(t, d.Val.Raw, "$EMPTYSTRING")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("$$ should be a literal $", func(t *testing.T) {
|
t.Run("$$ should be a literal $", func(t *testing.T) {
|
||||||
|
d := &Data{}
|
||||||
unmarshalingTest(t, `val: $$`, d)
|
unmarshalingTest(t, `val: $$`, d)
|
||||||
require.Equal(t, d.Val.Value(), "$")
|
require.Equal(t, d.Val.Value(), "$")
|
||||||
require.Equal(t, d.Val.Raw, "$$")
|
require.Equal(t, d.Val.Raw, "$$")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("$$ should be a literal $ and not expanded within a string", func(t *testing.T) {
|
t.Run("$$ should be a literal $ and not expanded within a string", func(t *testing.T) {
|
||||||
|
d := &Data{}
|
||||||
unmarshalingTest(t, `val: mY,Passwo$$rd`, d)
|
unmarshalingTest(t, `val: mY,Passwo$$rd`, d)
|
||||||
require.Equal(t, d.Val.Value(), "mY,Passwo$rd")
|
require.Equal(t, d.Val.Value(), "mY,Passwo$rd")
|
||||||
require.Equal(t, d.Val.Raw, "mY,Passwo$$rd")
|
require.Equal(t, d.Val.Raw, "mY,Passwo$$rd")
|
||||||
@@ -107,27 +113,29 @@ func TestValues(t *testing.T) {
|
|||||||
type Data struct {
|
type Data struct {
|
||||||
Val BoolValue `yaml:"val"`
|
Val BoolValue `yaml:"val"`
|
||||||
}
|
}
|
||||||
d := &Data{}
|
|
||||||
|
|
||||||
t.Run("Should unmarshal bool value", func(t *testing.T) {
|
t.Run("Should unmarshal bool value", func(t *testing.T) {
|
||||||
|
d := &Data{}
|
||||||
unmarshalingTest(t, `val: true`, d)
|
unmarshalingTest(t, `val: true`, d)
|
||||||
require.True(t, d.Val.Value())
|
require.True(t, d.Val.Value())
|
||||||
require.Equal(t, d.Val.Raw, "true")
|
require.Equal(t, d.Val.Raw, "true")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Should unmarshal explicit string", func(t *testing.T) {
|
t.Run("Should unmarshal explicit string", func(t *testing.T) {
|
||||||
|
d := &Data{}
|
||||||
unmarshalingTest(t, `val: "true"`, d)
|
unmarshalingTest(t, `val: "true"`, d)
|
||||||
require.True(t, d.Val.Value())
|
require.True(t, d.Val.Value())
|
||||||
require.Equal(t, d.Val.Raw, "true")
|
require.Equal(t, d.Val.Raw, "true")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Should unmarshal env var", func(t *testing.T) {
|
t.Run("Should unmarshal env var", func(t *testing.T) {
|
||||||
|
d := &Data{}
|
||||||
unmarshalingTest(t, `val: $BOOL`, d)
|
unmarshalingTest(t, `val: $BOOL`, d)
|
||||||
require.True(t, d.Val.Value())
|
require.True(t, d.Val.Value())
|
||||||
require.Equal(t, d.Val.Raw, "$BOOL")
|
require.Equal(t, d.Val.Raw, "$BOOL")
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Should ignore empty value", func(t *testing.T) {
|
t.Run("Should ignore empty value", func(t *testing.T) {
|
||||||
|
d := &Data{}
|
||||||
unmarshalingTest(t, `val: `, d)
|
unmarshalingTest(t, `val: `, d)
|
||||||
require.False(t, d.Val.Value())
|
require.False(t, d.Val.Value())
|
||||||
require.Equal(t, d.Val.Raw, "")
|
require.Equal(t, d.Val.Raw, "")
|
||||||
|
|||||||
Reference in New Issue
Block a user