Replace interface{} by any (#901)

Signed-off-by: yxxhero <aiopsclub@163.com>
This commit is contained in:
yxxhero
2023-06-16 10:49:05 +09:00
committed by GitHub
parent 94fe519ed5
commit c55fa0f765
46 changed files with 394 additions and 394 deletions
+27 -27
View File
@@ -7,11 +7,11 @@ import (
)
func TestMapUtil_StrKeys(t *testing.T) {
m := map[string]interface{}{
"a": []interface{}{
map[string]interface{}{
"b": []interface{}{
map[string]interface{}{
m := map[string]any{
"a": []any{
map[string]any{
"b": []any{
map[string]any{
"c": "C",
},
},
@@ -24,10 +24,10 @@ func TestMapUtil_StrKeys(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
a := r["a"].([]interface{})
a0 := a[0].(map[string]interface{})
b := a0["b"].([]interface{})
b0 := b[0].(map[string]interface{})
a := r["a"].([]any)
a0 := a[0].(map[string]any)
b := a0["b"].([]any)
b0 := b[0].(map[string]any)
c := b0["c"]
if c != "C" {
@@ -36,11 +36,11 @@ func TestMapUtil_StrKeys(t *testing.T) {
}
func TestMapUtil_IFKeys(t *testing.T) {
m := map[interface{}]interface{}{
"a": []interface{}{
map[interface{}]interface{}{
"b": []interface{}{
map[interface{}]interface{}{
m := map[any]any{
"a": []any{
map[any]any{
"b": []any{
map[any]any{
"c": "C",
},
},
@@ -53,10 +53,10 @@ func TestMapUtil_IFKeys(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
a := r["a"].([]interface{})
a0 := a[0].(map[string]interface{})
b := a0["b"].([]interface{})
b0 := b[0].(map[string]interface{})
a := r["a"].([]any)
a0 := a[0].(map[string]any)
b := a0["b"].([]any)
b0 := b[0].(map[string]any)
c := b0["c"]
if c != "C" {
@@ -65,13 +65,13 @@ func TestMapUtil_IFKeys(t *testing.T) {
}
func TestMapUtil_KeyArg(t *testing.T) {
m := map[string]interface{}{}
m := map[string]any{}
key := []string{"a", "b", "c"}
Set(m, key, "C")
c := (((m["a"].(map[string]interface{}))["b"]).(map[string]interface{}))["c"]
c := (((m["a"].(map[string]any))["b"]).(map[string]any))["c"]
if c != "C" {
t.Errorf("unexpected c: expected=C, got=%s", c)
@@ -79,13 +79,13 @@ func TestMapUtil_KeyArg(t *testing.T) {
}
func TestMapUtil_IndexedKeyArg(t *testing.T) {
m := map[string]interface{}{}
m := map[string]any{}
key := []string{"a", "b[0]", "c"}
Set(m, key, "C")
c := (((m["a"].(map[string]interface{}))["b"].([]interface{}))[0].(map[string]interface{}))["c"]
c := (((m["a"].(map[string]any))["b"].([]any))[0].(map[string]any))["c"]
if c != "C" {
t.Errorf("unexpected c: expected=C, got=%s", c)
@@ -96,27 +96,27 @@ func TestMapUtil_IndexedKeyArg2(t *testing.T) {
cases := []struct {
name string
stateValuesSet []string
want map[string]interface{}
want map[string]any
}{
{
name: "IndexedKeyArg",
stateValuesSet: []string{"myvalues[0]=HELLO,myvalues[1]=HELMFILE"},
want: map[string]interface{}{"myvalues": []interface{}{"HELLO", "HELMFILE"}},
want: map[string]any{"myvalues": []any{"HELLO", "HELMFILE"}},
},
{
name: "two state value",
stateValuesSet: []string{"myvalues[0]=HELLO,myvalues[1]=HELMFILE", "myvalues[2]=HELLO"},
want: map[string]interface{}{"myvalues": []interface{}{"HELLO", "HELMFILE", "HELLO"}},
want: map[string]any{"myvalues": []any{"HELLO", "HELMFILE", "HELLO"}},
},
{
name: "different key",
stateValuesSet: []string{"myvalues[0]=HELLO,key2[0]=HELMFILE", "myvalues[1]=HELLO2"},
want: map[string]interface{}{"myvalues": []interface{}{"HELLO", "HELLO2"}, "key2": []interface{}{"HELMFILE"}},
want: map[string]any{"myvalues": []any{"HELLO", "HELLO2"}, "key2": []any{"HELMFILE"}},
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
set := map[string]interface{}{}
set := map[string]any{}
for i := range c.stateValuesSet {
ops := strings.Split(c.stateValuesSet[i], ",")
for j := range ops {