what-changed operational

the code is working, the tests are passing. There is a lot more to check, but it's a good time to bring the feature into main.
This commit is contained in:
Dave Shanley
2022-11-18 10:47:39 -05:00
parent b510be3563
commit 9d8d6e36ea
8 changed files with 133 additions and 69 deletions

View File

@@ -3,18 +3,41 @@
package what_changed
//func TestCompareOpenAPIDocuments(t *testing.T) {
//
// original, _ := ioutil.ReadFile("../test_specs/burgershop.openapi.yaml")
// modified, _ := ioutil.ReadFile("../test_specs/burgershop.openapi-modified.yaml")
// infoOrig, _ := datamodel.ExtractSpecInfo(original)
// infoMod, _ := datamodel.ExtractSpecInfo(modified)
//
// origDoc, _ := v3.CreateDocument(infoOrig)
// modDoc, _ := v3.CreateDocument(infoMod)
//
// changes := CompareOpenAPIDocuments(origDoc, modDoc)
//
// assert.Nil(t, changes)
//
//}
import (
"github.com/pb33f/libopenapi/datamodel"
v3 "github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/stretchr/testify/assert"
"io/ioutil"
"testing"
)
func TestCompareOpenAPIDocuments(t *testing.T) {
original, _ := ioutil.ReadFile("../test_specs/burgershop.openapi.yaml")
modified, _ := ioutil.ReadFile("../test_specs/burgershop.openapi-modified.yaml")
infoOrig, _ := datamodel.ExtractSpecInfo(original)
infoMod, _ := datamodel.ExtractSpecInfo(modified)
origDoc, _ := v3.CreateDocument(infoOrig)
modDoc, _ := v3.CreateDocument(infoMod)
changes := CompareOpenAPIDocuments(origDoc, modDoc)
assert.Equal(t, 1, changes.TotalChanges())
assert.Equal(t, 0, changes.TotalBreakingChanges())
}
func Benchmark_CompareOpenAPIDocuments(b *testing.B) {
original, _ := ioutil.ReadFile("../test_specs/burgershop.openapi.yaml")
modified, _ := ioutil.ReadFile("../test_specs/burgershop.openapi-modified.yaml")
infoOrig, _ := datamodel.ExtractSpecInfo(original)
infoMod, _ := datamodel.ExtractSpecInfo(modified)
origDoc, _ := v3.CreateDocument(infoOrig)
modDoc, _ := v3.CreateDocument(infoMod)
for i := 0; i < b.N; i++ {
CompareOpenAPIDocuments(origDoc, modDoc)
}
}