More coverage tuning

This commit is contained in:
Dave Shanley
2023-03-26 06:04:11 -04:00
parent 33bd9621c5
commit 1bc04418db
4 changed files with 22 additions and 24 deletions

View File

@@ -16,7 +16,7 @@ type DocumentConfiguration struct {
BaseURL *url.URL
// If resolving locally, the BasePath will be the root from which relative references will be resolved from.
// It usually location of the root specification.
// It's usually the location of the root specification.
BasePath string // set the Base Path for resolving relative references if the spec is exploded.
// AllowFileReferences will allow the index to locate relative file references. This is disabled by default.

View File

@@ -0,0 +1,21 @@
// Copyright 2023 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package datamodel
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestNewClosedDocumentConfiguration(t *testing.T) {
cfg := NewClosedDocumentConfiguration()
assert.False(t, cfg.AllowRemoteReferences)
assert.False(t, cfg.AllowFileReferences)
}
func TestNewOpenDocumentConfiguration(t *testing.T) {
cfg := NewOpenDocumentConfiguration()
assert.True(t, cfg.AllowRemoteReferences)
assert.True(t, cfg.AllowFileReferences)
}

View File

@@ -19,7 +19,6 @@ import (
"github.com/pb33f/libopenapi/datamodel/low/v2"
"github.com/pb33f/libopenapi/datamodel/low/v3"
"github.com/pb33f/libopenapi/what-changed/model"
"reflect"
)
// CompareOpenAPIDocuments will compare left (original) and right (updated) OpenAPI 3+ documents and extract every change
@@ -34,24 +33,4 @@ func CompareOpenAPIDocuments(original, updated *v3.Document) *model.DocumentChan
// or removed and which of those changes were breaking.
func CompareSwaggerDocuments(original, updated *v2.Swagger) *model.DocumentChanges {
return model.CompareDocuments(original, updated)
}
func ExtractFlatChanges(changes *model.DocumentChanges) []*model.Change {
return extractChanges(changes)
}
func extractChanges(anything any) []*model.Change {
vo := reflect.ValueOf(anything)
switch vo.Kind() {
case reflect.Ptr:
extractChanges(vo.Elem().Interface())
case reflect.Slice:
panic("slice not supported")
case reflect.Struct:
extractChanges(vo.Elem().Interface())
}
return nil
}

View File

@@ -26,10 +26,8 @@ func TestCompareOpenAPIDocuments(t *testing.T) {
changes := CompareOpenAPIDocuments(origDoc, modDoc)
assert.Equal(t, 72, changes.TotalChanges())
assert.Equal(t, 17, changes.TotalBreakingChanges())
//
//out, _ := json.MarshalIndent(changes, "", " ")
//_ = ioutil.WriteFile("outputv3.json", out, 0776)
}
func TestCompareSwaggerDocuments(t *testing.T) {