mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 10:20:29 -06:00
062d255124
* replace ioutil.ReadFile -> os.ReadFile * replace ioutil.ReadAll -> io.ReadAll * replace ioutil.TempFile -> os.CreateTemp * replace ioutil.NopCloser -> io.NopCloser * replace ioutil.WriteFile -> os.WriteFile * replace ioutil.TempDir -> os.MkdirTemp * replace ioutil.Discard -> io.Discard
39 lines
847 B
Go
39 lines
847 B
Go
package httpclient
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCountBytesReader(t *testing.T) {
|
|
tcs := []struct {
|
|
body string
|
|
expectedBytesCount int64
|
|
}{
|
|
{body: "d", expectedBytesCount: 1},
|
|
{body: "dummy", expectedBytesCount: 5},
|
|
}
|
|
|
|
for index, tc := range tcs {
|
|
t.Run(fmt.Sprintf("Test CountBytesReader %d", index), func(t *testing.T) {
|
|
body := io.NopCloser(strings.NewReader(tc.body))
|
|
var actualBytesRead int64
|
|
|
|
readCloser := CountBytesReader(body, func(bytesRead int64) {
|
|
actualBytesRead = bytesRead
|
|
})
|
|
|
|
bodyBytes, err := io.ReadAll(readCloser)
|
|
require.NoError(t, err)
|
|
err = readCloser.Close()
|
|
require.NoError(t, err)
|
|
require.Equal(t, tc.expectedBytesCount, actualBytesRead)
|
|
require.Equal(t, string(bodyBytes), tc.body)
|
|
})
|
|
}
|
|
}
|