mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 20:47:44 +00:00
Working through more coverage
adding more tests. Signed-off-by: quobix <dave@quobix.com>
This commit is contained in:
@@ -215,7 +215,17 @@ func NewRolodex(indexConfig *SpecIndexConfig) *Rolodex {
|
||||
}
|
||||
|
||||
func (r *Rolodex) GetIgnoredCircularReferences() []*CircularReferenceResult {
|
||||
return r.ignoredCircularReferences
|
||||
debounced := make(map[string]*CircularReferenceResult)
|
||||
for _, c := range r.ignoredCircularReferences {
|
||||
if _, ok := debounced[c.LoopPoint.FullDefinition]; !ok {
|
||||
debounced[c.LoopPoint.FullDefinition] = c
|
||||
}
|
||||
}
|
||||
var debouncedResults []*CircularReferenceResult
|
||||
for _, v := range debounced {
|
||||
debouncedResults = append(debouncedResults, v)
|
||||
}
|
||||
return debouncedResults
|
||||
}
|
||||
|
||||
func (r *Rolodex) GetIndexingDuration() time.Duration {
|
||||
|
||||
@@ -198,7 +198,7 @@ func NewRemoteFSWithConfig(specIndexConfig *SpecIndexConfig) (*RemoteFS, error)
|
||||
} else {
|
||||
// default http client
|
||||
client := &http.Client{
|
||||
Timeout: time.Second * 60,
|
||||
Timeout: time.Second * 120,
|
||||
}
|
||||
rfs.RemoteHandlerFunc = func(url string) (*http.Response, error) {
|
||||
return client.Get(url)
|
||||
|
||||
@@ -438,7 +438,7 @@ components:
|
||||
assert.Len(t, rolodex.GetCaughtErrors(), 0)
|
||||
|
||||
// multiple loops across two files
|
||||
assert.Len(t, rolodex.GetIgnoredCircularReferences(), 3)
|
||||
assert.Len(t, rolodex.GetIgnoredCircularReferences(), 1)
|
||||
}
|
||||
|
||||
func TestRolodex_IndexCircularLookup_PolyItemsHttpOnly(t *testing.T) {
|
||||
@@ -505,12 +505,18 @@ components:
|
||||
required:
|
||||
- muffins
|
||||
properties:
|
||||
chuffins:
|
||||
type: object
|
||||
allOf:
|
||||
- $ref: "https://kjahsdkjahdkjashdas.com/third.yaml"
|
||||
buffins:
|
||||
type: object
|
||||
allOf:
|
||||
- $ref: "https://kjahsdkjahdkjashdas.com/second.yaml#/"
|
||||
muffins:
|
||||
type: object
|
||||
anyOf:
|
||||
- $ref: "https://kjahsdkjahdkjashdas.com/second.yaml#/components/schemas/CircleTest"
|
||||
- $ref: "https://kjahsdkjahdkjashdas.com/second.yaml#/"
|
||||
- $ref: "https://kjahsdkjahdkjashdas.com/third.yaml"
|
||||
`
|
||||
|
||||
var rootNode yaml.Node
|
||||
@@ -536,7 +542,7 @@ components:
|
||||
assert.Len(t, rolodex.GetCaughtErrors(), 0)
|
||||
|
||||
// should only be a single loop.
|
||||
assert.Len(t, rolodex.GetIgnoredCircularReferences(), 3)
|
||||
assert.Len(t, rolodex.GetIgnoredCircularReferences(), 1)
|
||||
assert.Equal(t, rolodex.GetRootIndex().GetResolver().GetIndexesVisited(), 6)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package index
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/pb33f/libopenapi/utils"
|
||||
"log"
|
||||
@@ -121,8 +122,9 @@ func TestSpecIndex_DigitalOcean(t *testing.T) {
|
||||
// create a handler that uses an env variable to capture any GITHUB_TOKEN in the OS ENV
|
||||
// and inject it into the request header, so this does not fail when running lots of local tests.
|
||||
if os.Getenv("GITHUB_TOKEN") != "" {
|
||||
fmt.Println("GITHUB_TOKEN found, setting remote handler func")
|
||||
client := &http.Client{
|
||||
Timeout: time.Second * 60,
|
||||
Timeout: time.Second * 120,
|
||||
}
|
||||
remoteFS.SetRemoteHandlerFunc(func(url string) (*http.Response, error) {
|
||||
request, _ := http.NewRequest(http.MethodGet, url, nil)
|
||||
@@ -233,7 +235,9 @@ func TestSpecIndex_DigitalOcean_LookupsNotAllowed(t *testing.T) {
|
||||
cf := &SpecIndexConfig{}
|
||||
cf.AvoidBuildIndex = true
|
||||
cf.AvoidCircularReferenceCheck = true
|
||||
cf.Logger = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
|
||||
var op []byte
|
||||
buf := bytes.NewBuffer(op)
|
||||
cf.Logger = slog.New(slog.NewJSONHandler(buf, &slog.HandlerOptions{
|
||||
Level: slog.LevelError,
|
||||
}))
|
||||
|
||||
@@ -282,7 +286,9 @@ func TestSpecIndex_BaseURLError(t *testing.T) {
|
||||
cf.AvoidBuildIndex = true
|
||||
cf.AllowRemoteLookup = true
|
||||
cf.AvoidCircularReferenceCheck = true
|
||||
cf.Logger = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{
|
||||
var op []byte
|
||||
buf := bytes.NewBuffer(op)
|
||||
cf.Logger = slog.New(slog.NewJSONHandler(buf, &slog.HandlerOptions{
|
||||
Level: slog.LevelError,
|
||||
}))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user