mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-07 20:47:45 +00:00
Who would have thought the what-changed tool would be the key to ensuring accuracy on the models.
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package what_changed
|
|
|
|
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, 30, changes.TotalChanges())
|
|
assert.Equal(t, 6, 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)
|
|
}
|
|
}
|