Skip to content

Commit

Permalink
feat: added unit tests for breaking changes check
Browse files Browse the repository at this point in the history
  • Loading branch information
RaduPetreTarean committed Aug 20, 2024
1 parent 1b93237 commit e93f2c8
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions internal/simplebuild/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,75 @@ func TestAnnotate(t *testing.T) {
})
}

func TestCheckBreakingChanges(t *testing.T) {
c := qt.New(t)

c.Run("detects breaking changes between versions", func(c *qt.C) {
paths1 := openapi3.Paths{}
paths1.Set("/foo", &openapi3.PathItem{
Get: &openapi3.Operation{},
})

paths2 := openapi3.Paths{}
paths2.Set("/foo", &openapi3.PathItem{
Post: &openapi3.Operation{},
})

doc1 := &openapi3.T{
Paths: &paths1,
}
doc2 := &openapi3.T{
Paths: &paths2,
}

docs := simplebuild.DocSet{
{
VersionDate: time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC),
Doc: doc1,
},
{
VersionDate: time.Date(2024, 2, 1, 0, 0, 0, 0, time.UTC),
Doc: doc2,
},
}

err := simplebuild.CheckBreakingChanges(docs)
c.Assert(err, qt.IsNil, qt.Commentf("expected breaking change to be detected"))
})

c.Run("no breaking changes between versions", func(c *qt.C) {
paths1 := openapi3.Paths{}
paths1.Set("/foo", &openapi3.PathItem{
Get: &openapi3.Operation{},
})

paths2 := openapi3.Paths{}
paths2.Set("/foo", &openapi3.PathItem{
Get: &openapi3.Operation{},
})

doc1 := &openapi3.T{
Paths: &paths1,
}
doc2 := &openapi3.T{
Paths: &paths2,
}

docs := simplebuild.DocSet{
{
VersionDate: time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC),
Doc: doc1,
},
{
VersionDate: time.Date(2024, 2, 1, 0, 0, 0, 0, time.UTC),
Doc: doc2,
},
}

err := simplebuild.CheckBreakingChanges(docs)
c.Assert(err, qt.Not(qt.IsNil), qt.Commentf("expected no breaking changes"))
})
}
func compareDocs(a, b simplebuild.VersionedDoc) int {
return a.VersionDate.Compare(b.VersionDate)
}
Expand Down

0 comments on commit e93f2c8

Please sign in to comment.