Skip to content

Commit 3b8312b

Browse files
committed
move tests
1 parent 17fa5e8 commit 3b8312b

File tree

2 files changed

+93
-60
lines changed

2 files changed

+93
-60
lines changed

tools/cli/internal/apiversion/version_test.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package apiversion
1616

1717
import (
18+
"github.com/getkin/kin-openapi/openapi3"
1819
"testing"
1920
"time"
2021

@@ -402,3 +403,95 @@ func TestNew_WithVersion(t *testing.T) {
402403
})
403404
}
404405
}
406+
407+
func TestFindLatestContentVersionMatched(t *testing.T) {
408+
testCases := []struct {
409+
name string
410+
targetVersion string
411+
expectedMatch string
412+
}{
413+
{
414+
name: "exact match 2023-01-01",
415+
targetVersion: "2023-01-01",
416+
expectedMatch: "2023-01-01",
417+
},
418+
{
419+
name: "exact match 2023-11-15",
420+
targetVersion: "2023-11-15",
421+
expectedMatch: "2023-11-15",
422+
},
423+
{
424+
name: "exact match 2024-05-30",
425+
targetVersion: "2024-05-30",
426+
expectedMatch: "2024-05-30",
427+
},
428+
{
429+
name: "approx match 2023-01-01",
430+
targetVersion: "2023-01-02",
431+
expectedMatch: "2023-01-01",
432+
},
433+
{
434+
name: "approx match 2023-01-01",
435+
targetVersion: "2023-01-31",
436+
expectedMatch: "2023-01-01",
437+
},
438+
{
439+
name: "approx match 2023-02-01",
440+
targetVersion: "2023-02-20",
441+
expectedMatch: "2023-02-01",
442+
},
443+
{
444+
name: "future date",
445+
targetVersion: "2030-02-20",
446+
expectedMatch: "2024-05-30",
447+
},
448+
{
449+
name: "past date",
450+
targetVersion: "1999-02-20",
451+
expectedMatch: "1999-02-20",
452+
},
453+
}
454+
455+
for _, tt := range testCases {
456+
t.Run(tt.name, func(t *testing.T) {
457+
t.Parallel()
458+
targetVersion, err := New(WithVersion(tt.targetVersion))
459+
require.NoError(t, err)
460+
r := FindLatestContentVersionMatched(oasOperationAllVersions(), targetVersion)
461+
// transform time to str with format "2006-01-02"
462+
assert.Equal(t, tt.expectedMatch, r.String())
463+
})
464+
}
465+
}
466+
467+
func oasOperationAllVersions() *openapi3.Operation {
468+
responses := &openapi3.Responses{}
469+
responses.Set("200", &openapi3.ResponseRef{
470+
Value: &openapi3.Response{
471+
Content: map[string]*openapi3.MediaType{
472+
"application/vnd.atlas.2023-01-01+json": {},
473+
"application/vnd.atlas.2023-01-01+csv": {},
474+
"application/vnd.atlas.2023-02-01+json": {},
475+
"application/vnd.atlas.2023-10-01+json": {},
476+
"application/vnd.atlas.2023-11-15+json": {},
477+
"application/vnd.atlas.2024-05-30+json": {},
478+
},
479+
},
480+
})
481+
482+
return &openapi3.Operation{
483+
OperationID: "operationId",
484+
Responses: responses,
485+
RequestBody: &openapi3.RequestBodyRef{
486+
Value: &openapi3.RequestBody{
487+
Content: map[string]*openapi3.MediaType{
488+
"application/vnd.atlas.2023-01-01+json": {},
489+
"application/vnd.atlas.2023-02-01+json": {},
490+
"application/vnd.atlas.2023-10-01+json": {},
491+
"application/vnd.atlas.2023-11-15+json": {},
492+
"application/vnd.atlas.2024-05-30+json": {},
493+
},
494+
},
495+
},
496+
}
497+
}

tools/cli/internal/openapi/filter/versioning_test.go

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -23,66 +23,6 @@ import (
2323
"github.com/stretchr/testify/require"
2424
)
2525

26-
func TestPathFilter_getLatestVersionMatch(t *testing.T) {
27-
testCases := []struct {
28-
name string
29-
targetVersion string
30-
expectedMatch string
31-
}{
32-
{
33-
name: "exact match 2023-01-01",
34-
targetVersion: "2023-01-01",
35-
expectedMatch: "2023-01-01",
36-
},
37-
{
38-
name: "exact match 2023-11-15",
39-
targetVersion: "2023-11-15",
40-
expectedMatch: "2023-11-15",
41-
},
42-
{
43-
name: "exact match 2024-05-30",
44-
targetVersion: "2024-05-30",
45-
expectedMatch: "2024-05-30",
46-
},
47-
{
48-
name: "approx match 2023-01-01",
49-
targetVersion: "2023-01-02",
50-
expectedMatch: "2023-01-01",
51-
},
52-
{
53-
name: "approx match 2023-01-01",
54-
targetVersion: "2023-01-31",
55-
expectedMatch: "2023-01-01",
56-
},
57-
{
58-
name: "approx match 2023-02-01",
59-
targetVersion: "2023-02-20",
60-
expectedMatch: "2023-02-01",
61-
},
62-
{
63-
name: "future date",
64-
targetVersion: "2030-02-20",
65-
expectedMatch: "2024-05-30",
66-
},
67-
{
68-
name: "past date",
69-
targetVersion: "1999-02-20",
70-
expectedMatch: "1999-02-20",
71-
},
72-
}
73-
74-
for _, tt := range testCases {
75-
t.Run(tt.name, func(t *testing.T) {
76-
targetVersion, err := apiversion.New(apiversion.WithVersion(tt.targetVersion))
77-
require.NoError(t, err)
78-
r, err := apiversion.FindLatestContentVersionMatched(oasOperationAllVersions(), targetVersion)
79-
require.NoError(t, err)
80-
// transform time to str with format "2006-01-02"
81-
assert.Equal(t, tt.expectedMatch, r.String())
82-
})
83-
}
84-
}
85-
8626
func TestPathFilter_processPathItem(t *testing.T) {
8727
version, err := apiversion.New(apiversion.WithVersion("2023-11-15"))
8828
require.NoError(t, err)

0 commit comments

Comments
 (0)