2022-12-23 17:35:35 +00:00
|
|
|
package frostfs
|
2020-09-08 08:38:49 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-10-26 14:46:15 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2020-09-08 08:38:49 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseConfig(t *testing.T) {
|
|
|
|
var (
|
2020-11-05 13:26:28 +00:00
|
|
|
id = []byte("id")
|
2020-09-08 08:38:49 +00:00
|
|
|
key = []byte("key")
|
|
|
|
value = []byte("value")
|
|
|
|
)
|
|
|
|
|
|
|
|
t.Run("wrong number of parameters", func(t *testing.T) {
|
2020-10-26 14:46:15 +00:00
|
|
|
prms := []stackitem.Item{
|
|
|
|
stackitem.NewMap(),
|
2020-09-08 08:38:49 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 10:06:08 +00:00
|
|
|
_, err := ParseConfig(createNotifyEventFromItems(prms))
|
2024-12-06 10:59:15 +00:00
|
|
|
require.Error(t, err)
|
2020-09-08 08:38:49 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("wrong first parameter", func(t *testing.T) {
|
2021-10-22 10:06:08 +00:00
|
|
|
_, err := ParseConfig(createNotifyEventFromItems([]stackitem.Item{
|
2020-10-26 14:46:15 +00:00
|
|
|
stackitem.NewMap(),
|
2021-10-22 10:06:08 +00:00
|
|
|
}))
|
2020-09-08 08:38:49 +00:00
|
|
|
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("wrong second parameter", func(t *testing.T) {
|
2021-10-22 10:06:08 +00:00
|
|
|
_, err := ParseConfig(createNotifyEventFromItems([]stackitem.Item{
|
2020-11-05 13:26:28 +00:00
|
|
|
stackitem.NewByteArray(id),
|
|
|
|
stackitem.NewMap(),
|
2021-10-22 10:06:08 +00:00
|
|
|
}))
|
2020-11-05 13:26:28 +00:00
|
|
|
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("wrong third parameter", func(t *testing.T) {
|
2021-10-22 10:06:08 +00:00
|
|
|
_, err := ParseConfig(createNotifyEventFromItems([]stackitem.Item{
|
2020-11-05 13:26:28 +00:00
|
|
|
stackitem.NewByteArray(id),
|
2020-10-26 14:46:15 +00:00
|
|
|
stackitem.NewByteArray(key),
|
|
|
|
stackitem.NewMap(),
|
2021-10-22 10:06:08 +00:00
|
|
|
}))
|
2020-09-08 08:38:49 +00:00
|
|
|
|
|
|
|
require.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("correct", func(t *testing.T) {
|
2021-10-22 10:06:08 +00:00
|
|
|
ev, err := ParseConfig(createNotifyEventFromItems([]stackitem.Item{
|
2020-11-05 13:26:28 +00:00
|
|
|
stackitem.NewByteArray(id),
|
2020-10-26 14:46:15 +00:00
|
|
|
stackitem.NewByteArray(key),
|
|
|
|
stackitem.NewByteArray(value),
|
2021-10-22 10:06:08 +00:00
|
|
|
}))
|
2020-09-08 08:38:49 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Equal(t, Config{
|
2023-04-26 13:25:50 +00:00
|
|
|
IDValue: id,
|
|
|
|
KeyValue: key,
|
|
|
|
ValueValue: value,
|
2020-09-08 08:38:49 +00:00
|
|
|
}, ev)
|
|
|
|
})
|
|
|
|
}
|