Skip to content

Commit

Permalink
fix: filters out wip versions from simplebuild collation
Browse files Browse the repository at this point in the history
  • Loading branch information
tinygrasshopper committed Oct 9, 2024
1 parent 5ffe392 commit 2441e56
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 3 deletions.
7 changes: 4 additions & 3 deletions internal/simplebuild/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ type VersionedDoc struct {
type DocSet []VersionedDoc

func (ops Operations) Build(startVersion vervet.Version) DocSet {
filteredOps := filterOutExperimentalVersions(ops)
filteredOps := filterBetaAndGAVersions(ops)
versionDates := filteredOps.VersionDates()
versionDates = filterVersionByStartDate(versionDates, startVersion.Date)
output := make(DocSet, len(versionDates))
Expand All @@ -165,12 +165,13 @@ func (ops Operations) Build(startVersion vervet.Version) DocSet {
return output
}

func filterOutExperimentalVersions(ops Operations) Operations {
func filterBetaAndGAVersions(ops Operations) Operations {
filteredOps := make(Operations, len(ops))
for opKey, versionSet := range ops {
filteredVersionSet := VersionSet{}
for _, versionedOp := range versionSet {
if versionedOp.Version.Stability == vervet.StabilityExperimental {
if versionedOp.Version.Stability != vervet.StabilityGA &&
versionedOp.Version.Stability != vervet.StabilityBeta {
continue
}
filteredVersionSet = append(filteredVersionSet, versionedOp)
Expand Down
76 changes: 76 additions & 0 deletions internal/simplebuild/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,82 @@ func TestBuild(t *testing.T) {
c.Assert(output[2].Doc.Paths.Value("/experimental-path-before-pivot-date"), qt.IsNil)
c.Assert(output[2].Doc.Paths.Value("/experimental-path"), qt.IsNil)
})
c.Run("wip version are filtered out", func(c *qt.C) {
versionBetaA := vervet.MustParseVersion("2024-01-01~beta")
versionGA := vervet.MustParseVersion("2024-01-02")
versionBetaB := vervet.MustParseVersion("2024-01-03~beta")
versionWip := vervet.MustParseVersion("2024-01-04~wip")
versionWipBeforePivotDate := vervet.MustParseVersion("2023-01-01~wip")

getFoo := openapi3.NewOperation()
postFoo := openapi3.NewOperation()
getBar := openapi3.NewOperation()

ops := simplebuild.Operations{
simplebuild.OpKey{
Path: "/foo",
Method: "GET",
}: simplebuild.VersionSet{simplebuild.VersionedOp{
Version: versionGA,
Operation: getFoo,
ResourceName: "foo",
}},
simplebuild.OpKey{
Path: "/foo",
Method: "POST",
}: simplebuild.VersionSet{simplebuild.VersionedOp{
Version: versionBetaB,
Operation: postFoo,
ResourceName: "foo",
}},
simplebuild.OpKey{
Path: "/bar",
Method: "GET",
}: simplebuild.VersionSet{simplebuild.VersionedOp{
Version: versionBetaA,
Operation: getBar,
ResourceName: "bar",
}},
simplebuild.OpKey{
Path: "/wip-path",
Method: "GET",
}: simplebuild.VersionSet{simplebuild.VersionedOp{
Version: versionWip,
Operation: openapi3.NewOperation(),
ResourceName: "wip-path",
}},
simplebuild.OpKey{
Path: "/wip-path-before-pivot-date",
Method: "GET",
}: simplebuild.VersionSet{simplebuild.VersionedOp{
Version: versionWipBeforePivotDate,
Operation: openapi3.NewOperation(),
ResourceName: "wip-path-before-pivot-date",
}},
}
output := ops.Build(vervet.MustParseVersion("2024-01-01"))

slices.SortFunc(output, compareDocs)

c.Assert(output, qt.HasLen, 3)

c.Assert(output[0].VersionDate, qt.Equals, versionBetaA.Date)
c.Assert(output[0].Doc.Paths.Value("/foo"), qt.IsNil)
c.Assert(output[0].Doc.Paths.Value("/bar").Get, qt.Equals, getBar)
c.Assert(output[0].Doc.Paths.Value("/wip-path-before-pivot-date"), qt.IsNil)

c.Assert(output[1].VersionDate, qt.Equals, versionGA.Date)
c.Assert(output[1].Doc.Paths.Value("/foo").Get, qt.Equals, getFoo)
c.Assert(output[1].Doc.Paths.Value("/foo").Post, qt.IsNil)
c.Assert(output[0].Doc.Paths.Value("/bar").Get, qt.Equals, getBar)

c.Assert(output[2].VersionDate, qt.Equals, versionBetaB.Date)
c.Assert(output[2].Doc.Paths.Value("/foo").Get, qt.Equals, getFoo)
c.Assert(output[2].Doc.Paths.Value("/foo").Post, qt.Equals, postFoo)
c.Assert(output[2].Doc.Paths.Value("/bar").Get, qt.Equals, getBar)
c.Assert(output[2].Doc.Paths.Value("/wip-path-before-pivot-date"), qt.IsNil)
c.Assert(output[2].Doc.Paths.Value("/wip-path"), qt.IsNil)
})
}

func TestAnnotate(t *testing.T) {
Expand Down

0 comments on commit 2441e56

Please sign in to comment.