2022-12-23 17:35:35 +00:00
|
|
|
package frostfs
|
2020-09-08 08:38:49 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
|
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))
|
2020-11-05 13:26:28 +00:00
|
|
|
require.EqualError(t, err, event.WrongNumberOfParameters(3, len(prms)).Error())
|
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{
|
2020-11-05 13:26:28 +00:00
|
|
|
id: id,
|
2020-09-08 08:38:49 +00:00
|
|
|
key: key,
|
|
|
|
value: value,
|
|
|
|
}, ev)
|
|
|
|
})
|
|
|
|
}
|