frostfs-http-gw/internal/handler/reader_test.go
Nikita Zinkevich 151e5bc1c8
All checks were successful
/ Vulncheck (pull_request) Successful in 1m17s
/ DCO (pull_request) Successful in 1m20s
/ Builds (1.22) (pull_request) Successful in 1m50s
/ Builds (1.23) (pull_request) Successful in 1m49s
/ Lint (pull_request) Successful in 2m41s
/ Tests (1.22) (pull_request) Successful in 1m44s
/ Tests (1.23) (pull_request) Successful in 1m41s
[#132] Update Go version
Signed-off-by: Nikita Zinkevich <n.zinkevich@yadro.com>
2024-08-29 10:42:20 +03:00

48 lines
1 KiB
Go

//go:build !integration
package handler
import (
"io"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestDetector(t *testing.T) {
txtContentType := "text/plain; charset=utf-8"
sb := strings.Builder{}
for i := 0; i < 10; i++ {
sb.WriteString("Some txt content. Content-Type must be detected properly by detector.")
}
for _, tc := range []struct {
Name string
ContentType string
Expected string
}{
{
Name: "less than 512b",
ContentType: txtContentType,
Expected: sb.String()[:256],
},
{
Name: "more than 512b",
ContentType: txtContentType,
Expected: sb.String(),
},
} {
t.Run(tc.Name, func(t *testing.T) {
contentType, data, err := readContentType(uint64(len(tc.Expected)),
func(uint64) (io.Reader, error) {
return strings.NewReader(tc.Expected), nil
},
)
require.NoError(t, err)
require.Equal(t, tc.ContentType, contentType)
require.True(t, strings.HasPrefix(tc.Expected, string(data)))
})
}
}