[#85] Add integration tests
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
5caac8f526
commit
d2b0532929
4 changed files with 733 additions and 1 deletions
|
@ -1,8 +1,10 @@
|
|||
package downloader
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
@ -41,3 +43,44 @@ func TestReader(t *testing.T) {
|
|||
require.Equal(t, data, res)
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
detector := newDetector()
|
||||
|
||||
go func() {
|
||||
detector.SetReader(bytes.NewBufferString(tc.Expected))
|
||||
detector.Detect()
|
||||
}()
|
||||
|
||||
detector.Wait()
|
||||
require.Equal(t, tc.ContentType, detector.contentType)
|
||||
|
||||
data, err := io.ReadAll(detector.MultiReader())
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, tc.Expected, string(data))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue