[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"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@@ -124,13 +125,19 @@ func (p *PostAction) Equals(input *PostAction) bool {
|
||||
|
||||
for key, value := range p.Integration.Context {
|
||||
inputValue, ok := input.Integration.Context[key]
|
||||
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
if value != inputValue {
|
||||
return false
|
||||
switch inputValue.(type) {
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
||||
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