@@ -153,7 +153,7 @@ func TestNewAPIVersionFromContentType(t *testing.T) {
153153 for _ , tt := range testCases {
154154 t .Run (tt .name , func (t * testing.T ) {
155155 t .Parallel ()
156- version , err := New (WithContent (tt .contentType ))
156+ version , err := New (withContent (tt .contentType ))
157157 if tt .wantErr {
158158 assert .Error (t , err )
159159 } else {
@@ -179,9 +179,67 @@ func TestApiVersion_WithFullContent(t *testing.T) {
179179 wantErr : false ,
180180 },
181181 {
182- name : "preview" ,
183- contentType : "application/vnd.atlas.preview+json" ,
182+ name : "csv" ,
183+ contentType : "application/vnd.atlas.2023-01-02+csv" ,
184+ contentValue : & openapi3.MediaType {},
185+
186+ expectedMatch : "2023-01-02" ,
187+ wantErr : false ,
188+ },
189+ {
190+ name : "yaml" ,
191+ contentType : "application/vnd.atlas.2030-02-20+yaml" ,
184192 contentValue : & openapi3.MediaType {},
193+ expectedMatch : "2030-02-20" ,
194+ wantErr : false ,
195+ },
196+ {
197+ name : "invalid" ,
198+
199+ contentType : "application/vnd.test.2023-01-01" ,
200+ contentValue : & openapi3.MediaType {},
201+ expectedMatch : "" ,
202+ wantErr : true ,
203+ },
204+ {
205+ name : "notVersioned" ,
206+ contentType : "application/json" ,
207+ contentValue : & openapi3.MediaType {},
208+ expectedMatch : "" ,
209+ wantErr : true ,
210+ },
211+ {
212+ name : "empty" ,
213+ contentType : "" ,
214+ contentValue : & openapi3.MediaType {},
215+ expectedMatch : "" ,
216+ wantErr : true ,
217+ },
218+ {
219+ name : "invalidFormat" ,
220+ contentType : "application/vnd.atlas.2023-01-01" ,
221+ expectedMatch : "" ,
222+ contentValue : & openapi3.MediaType {},
223+ wantErr : true ,
224+ },
225+ {
226+ name : "invalidDate" ,
227+ contentType : "application/vnd.atlas.2023111-01-01" ,
228+ expectedMatch : "" ,
229+ contentValue : & openapi3.MediaType {},
230+ wantErr : true ,
231+ },
232+
233+ {
234+ name : "preview" ,
235+ contentType : "application/vnd.atlas.preview+json" ,
236+ contentValue : & openapi3.MediaType {
237+ Extensions : map [string ]any {
238+ "x-xgen-preview" : map [string ]any {
239+ "public" : "true" ,
240+ },
241+ },
242+ },
185243 expectedMatch : "preview" ,
186244 wantErr : false ,
187245 },
@@ -198,6 +256,27 @@ func TestApiVersion_WithFullContent(t *testing.T) {
198256 expectedMatch : "private-preview-feature" ,
199257 wantErr : false ,
200258 },
259+ {
260+ name : "invalid-preview" ,
261+ contentType : "application/vnd.atlas.preview+json" ,
262+ contentValue : & openapi3.MediaType {
263+ Extensions : map [string ]any {
264+ "x-xgen-preview" : map [string ]any {
265+ "public" : "true" ,
266+ "name" : "feature" ,
267+ },
268+ },
269+ },
270+ expectedMatch : "private-preview-feature" ,
271+ wantErr : true ,
272+ },
273+ {
274+ name : "invalid-preview" ,
275+ contentType : "application/vnd.atlas.preview+json" ,
276+ contentValue : & openapi3.MediaType {},
277+ expectedMatch : "preview" ,
278+ wantErr : true ,
279+ },
201280 }
202281
203282 for _ , tt := range testCases {
@@ -207,6 +286,7 @@ func TestApiVersion_WithFullContent(t *testing.T) {
207286 if tt .wantErr {
208287 assert .Error (t , err )
209288 } else {
289+ require .NoError (t , err )
210290 assert .Equal (t , tt .expectedMatch , version .String ())
211291 }
212292 })
0 commit comments