44 "testing"
55
66 "github.com/stretchr/testify/assert"
7+ "github.com/stretchr/testify/require"
78)
89
910func TestBuildDocumentPath (t * testing.T ) {
@@ -34,16 +35,34 @@ func TestBuildDocumentPath(t *testing.T) {
3435 opts : DocumentPathOptions {UUID : "abc-123" , Format : "png" , Page : 3 },
3536 want : "abc-123/document/-/format/png/-/page/3/" ,
3637 },
38+ {
39+ name : "negative_page_ignored" ,
40+ opts : DocumentPathOptions {UUID : "abc-123" , Page : - 1 },
41+ want : "abc-123/document/-/format/pdf/" ,
42+ },
43+ {
44+ name : "zero_page_ignored" ,
45+ opts : DocumentPathOptions {UUID : "abc-123" , Format : "png" , Page : 0 },
46+ want : "abc-123/document/-/format/png/" ,
47+ },
3748 }
3849
3950 for _ , tt := range tests {
4051 t .Run (tt .name , func (t * testing.T ) {
4152 t .Parallel ()
42- assert .Equal (t , tt .want , BuildDocumentPath (tt .opts ))
53+ got , err := BuildDocumentPath (tt .opts )
54+ require .NoError (t , err )
55+ assert .Equal (t , tt .want , got )
4356 })
4457 }
4558}
4659
60+ func TestBuildDocumentPath_EmptyUUID (t * testing.T ) {
61+ t .Parallel ()
62+ _ , err := BuildDocumentPath (DocumentPathOptions {})
63+ assert .ErrorIs (t , err , errEmptyUUID )
64+ }
65+
4766func TestBuildVideoPath (t * testing.T ) {
4867 t .Parallel ()
4968
@@ -68,20 +87,60 @@ func TestBuildVideoPath(t *testing.T) {
6887 UUID : "abc-123" ,
6988 Format : "webm" ,
7089 Size : "640x480" ,
71- ResizeMode : "preserve_ratio" ,
72- Quality : "best" ,
90+ ResizeMode : ResizeModePreserveRatio ,
91+ Quality : QualityBest ,
7392 CutStart : "000:00:05.000" ,
7493 CutLength : "000:00:15.000" ,
7594 Thumbs : 10 ,
7695 },
7796 want : "abc-123/video/-/format/webm/-/size/640x480/preserve_ratio/-/quality/best/-/cut/000:00:05.000/000:00:15.000/-/thumbs~10/" ,
7897 },
98+ {
99+ name : "size_without_resize_mode" ,
100+ opts : VideoPathOptions {UUID : "abc-123" , Size : "1920x1080" },
101+ want : "abc-123/video/-/format/mp4/-/size/1920x1080/" ,
102+ },
103+ {
104+ name : "negative_thumbs_ignored" ,
105+ opts : VideoPathOptions {UUID : "abc-123" , Thumbs : - 5 },
106+ want : "abc-123/video/-/format/mp4/" ,
107+ },
108+ {
109+ name : "only_quality" ,
110+ opts : VideoPathOptions {UUID : "abc-123" , Quality : QualityLighter },
111+ want : "abc-123/video/-/format/mp4/-/quality/lighter/" ,
112+ },
113+ }
114+
115+ for _ , tt := range tests {
116+ t .Run (tt .name , func (t * testing.T ) {
117+ t .Parallel ()
118+ got , err := BuildVideoPath (tt .opts )
119+ require .NoError (t , err )
120+ assert .Equal (t , tt .want , got )
121+ })
122+ }
123+ }
124+
125+ func TestBuildVideoPath_Errors (t * testing.T ) {
126+ t .Parallel ()
127+
128+ tests := []struct {
129+ name string
130+ opts VideoPathOptions
131+ wantErr error
132+ }{
133+ {"empty_uuid" , VideoPathOptions {}, errEmptyUUID },
134+ {"resize_mode_without_size" , VideoPathOptions {UUID : "abc-123" , ResizeMode : "preserve_ratio" }, errResizeModeNoSize },
135+ {"cut_start_only" , VideoPathOptions {UUID : "abc-123" , CutStart : "000:00:05.000" }, errIncompleteCut },
136+ {"cut_length_only" , VideoPathOptions {UUID : "abc-123" , CutLength : "000:00:15.000" }, errIncompleteCut },
79137 }
80138
81139 for _ , tt := range tests {
82140 t .Run (tt .name , func (t * testing.T ) {
83141 t .Parallel ()
84- assert .Equal (t , tt .want , BuildVideoPath (tt .opts ))
142+ _ , err := BuildVideoPath (tt .opts )
143+ assert .ErrorIs (t , err , tt .wantErr )
85144 })
86145 }
87146}
0 commit comments