/
githubmirror
/
trivy
Обзор
Документация
Войти
/
githubmirror
/
trivy
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
pkg/x/io/counting_reader_test.go
64 строки
1 KB
DmitriyLewen
feat(image): save layers metadata into report (#8394)
23 апр 2025, 19:31
Не верифицирован
23 апр 2025, 19:31
a95cab0
Код
Авторство
О чём код?
package io import ( "bytes" "io" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestCountingReader(t *testing.T) { testCases := []struct { name string data []byte readSize int want int64 }{ { name: "empty data", data: []byte{}, readSize: 10, want: 0, }, { name: "small data single read", data: []byte("hello"), readSize: 10, want: 5, }, { name: "multiple reads", data: []byte("hello world"), readSize: 5, want: 11, }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { // Create a reader with test data reader := bytes.NewReader(tc.data) // Wrap with counter counter := NewCountingReader(reader) // Read all data buf := make([]byte, tc.readSize) for { n, err := counter.Read(buf) if err == io.EOF { break } require.NoError(t, err, "unexpected error during read") if n == 0 { break } } // Verify bytes read assert.Equal(t, tc.want, counter.BytesRead(), "BytesRead() should return correct count") }) } }