/
githubmirror
/
nbs
Обзор
Документация
Войти
/
githubmirror
/
nbs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
library/go/blockcodecs/integration/decoder_test.go
44 строки
906 B
svartmetal
[Disk Manager] add cloud/disk_manager target
18 дек 2023, 23:07
18 дек 2023, 23:07
5221f36
Код
Авторство
О чём код?
package integration import ( "bytes" "io" "testing" "github.com/stretchr/testify/require" "github.com/ydb-platform/nbs/library/go/blockcodecs" _ "github.com/ydb-platform/nbs/library/go/blockcodecs/all" ) func TestDecoder_CheckEOF(t *testing.T) { var buf bytes.Buffer data := []byte("hello") w := blockcodecs.NewEncoder(&buf, blockcodecs.FindCodecByName("null")) _, err := w.Write(data) require.NoError(t, err) require.NoError(t, w.Close()) checkOK := func(r io.Reader) { buf, err := io.ReadAll(r) require.NoError(t, err) require.Equal(t, buf, data) } d := blockcodecs.NewDecoder(bytes.NewBuffer(buf.Bytes())) checkOK(d) withTail := bytes.NewBuffer(buf.Bytes()) withTail.WriteByte('X') d = blockcodecs.NewDecoder(withTail) checkOK(d) withTail.Reset() d = blockcodecs.NewDecoder(withTail) d.SetCheckUnderlyingEOF(true) _, err = io.ReadAll(d) require.Error(t, err) }