[MM-28664] model/integration_action: fix panic for uncomparable types (#15514)
* model/integration_action: fix panic for uncomparable types * model/integration_action: improve performance * reflect review comments Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1e34bdac1f
Коммит
dc1b42390b
@@ -16,6 +16,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"math/big"
|
"math/big"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -124,13 +125,19 @@ func (p *PostAction) Equals(input *PostAction) bool {
|
|||||||
|
|
||||||
for key, value := range p.Integration.Context {
|
for key, value := range p.Integration.Context {
|
||||||
inputValue, ok := input.Integration.Context[key]
|
inputValue, ok := input.Integration.Context[key]
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if value != inputValue {
|
switch inputValue.(type) {
|
||||||
return false
|
case string, bool, int, float64:
|
||||||
|
if value != inputValue {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
if !reflect.DeepEqual(value, inputValue) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -161,3 +161,65 @@ func TestSubmitDialogResponseToJson(t *testing.T) {
|
|||||||
assert.Nil(t, r)
|
assert.Nil(t, r)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPostActionIntegrationEquals(t *testing.T) {
|
||||||
|
t.Run("equal uncomparable types", func(t *testing.T) {
|
||||||
|
pa1 := &PostAction{
|
||||||
|
Integration: &PostActionIntegration{
|
||||||
|
Context: map[string]interface{}{
|
||||||
|
"a": map[string]interface{}{
|
||||||
|
"a": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
pa2 := &PostAction{
|
||||||
|
Integration: &PostActionIntegration{
|
||||||
|
Context: map[string]interface{}{
|
||||||
|
"a": map[string]interface{}{
|
||||||
|
"a": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
require.True(t, pa1.Equals(pa2))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("equal comparable types", func(t *testing.T) {
|
||||||
|
pa1 := &PostAction{
|
||||||
|
Integration: &PostActionIntegration{
|
||||||
|
Context: map[string]interface{}{
|
||||||
|
"a": "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
pa2 := &PostAction{
|
||||||
|
Integration: &PostActionIntegration{
|
||||||
|
Context: map[string]interface{}{
|
||||||
|
"a": "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
require.True(t, pa1.Equals(pa2))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("non-equal types", func(t *testing.T) {
|
||||||
|
pa1 := &PostAction{
|
||||||
|
Integration: &PostActionIntegration{
|
||||||
|
Context: map[string]interface{}{
|
||||||
|
"a": map[string]interface{}{
|
||||||
|
"a": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
pa2 := &PostAction{
|
||||||
|
Integration: &PostActionIntegration{
|
||||||
|
Context: map[string]interface{}{
|
||||||
|
"a": "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
require.False(t, pa1.Equals(pa2))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user