Live video on the AT Protocol
1package media
2
3import (
4 "bytes"
5 "context"
6 "fmt"
7 "io"
8 "os"
9 "testing"
10
11 "github.com/stretchr/testify/require"
12 "go.uber.org/goleak"
13 "golang.org/x/sync/errgroup"
14 "stream.place/streamplace/pkg/gstinit"
15)
16
17func TestThumbnail(t *testing.T) {
18 gstinit.InitGST()
19 before := getLeakCount(t)
20 defer checkGStreamerLeaks(t, before)
21 ignore := goleak.IgnoreCurrent()
22 defer goleak.VerifyNone(t, ignore)
23
24 // Open input file
25 inputFile, err := os.Open(getFixture("sample-segment.mp4"))
26 require.NoError(t, err)
27 defer inputFile.Close()
28 bs, err := io.ReadAll(inputFile)
29 require.NoError(t, err)
30
31 ctx := context.Background()
32 g, ctx := errgroup.WithContext(ctx)
33
34 for i := 0; i < streamplaceTestCount; i++ {
35 g.Go(func() error {
36 thumbnail := bytes.Buffer{}
37 // thumbnailCtx = log.WithDebugValue(ctx, map[string]map[string]int{"function": {"Thumbnail": 9}})
38 err := Thumbnail(ctx, bytes.NewReader(bs), &thumbnail)
39 if err != nil {
40 return err
41 }
42 if thumbnail.Len() == 0 {
43 return fmt.Errorf("thumbnail buffer is empty")
44 }
45 require.Equal(t, thumbnail.Len(), 1418910)
46 return nil
47 })
48 }
49
50 err = g.Wait()
51 require.NoError(t, err)
52}