fix: tests

This commit is contained in:
Tristan Cartledge
2023-12-01 18:25:15 +00:00
parent 6661f3a4e3
commit 94fb310643
3 changed files with 12 additions and 21 deletions

View File

@@ -676,6 +676,9 @@ func ExtractMapExtensions[PT Buildable[N], N any](
continue // yo, don't pay any attention to extensions, not here anyway.
}
}
if currentLabelNode == nil && i%2 != 0 {
continue // we need a label node first, and we don't have one because of extensions.
}
en = utils.NodeAlias(en)
if i%2 == 0 {

View File

@@ -28,6 +28,10 @@ func (r Reference) IsReference() bool {
}
func (r Reference) GetReferenceNode() *yaml.Node {
if r.IsReference() && r.refNode == nil {
return utils.CreateRefNode(r.reference)
}
return r.refNode
}

View File

@@ -6,8 +6,6 @@ package index
import (
"bytes"
"fmt"
"github.com/pb33f/libopenapi/utils"
"golang.org/x/sync/syncmap"
"log"
"log/slog"
"net/http"
@@ -19,12 +17,14 @@ import (
"testing"
"time"
"github.com/pb33f/libopenapi/utils"
"golang.org/x/sync/syncmap"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
)
func TestSpecIndex_GetCache(t *testing.T) {
petstore, _ := os.ReadFile("../test_specs/petstorev3.json")
var rootNode yaml.Node
_ = yaml.Unmarshal(petstore, &rootNode)
@@ -55,7 +55,6 @@ func TestSpecIndex_GetCache(t *testing.T) {
loaded, ok = extCache.Load("test2")
assert.Nil(t, loaded)
assert.False(t, ok)
}
func TestSpecIndex_ExtractRefsStripe(t *testing.T) {
@@ -188,7 +187,6 @@ func TestSpecIndex_DigitalOcean(t *testing.T) {
rolo.CheckForCircularReferences()
assert.Len(t, rolo.GetCaughtErrors(), 0)
assert.Len(t, rolo.GetIgnoredCircularReferences(), 0)
}
func TestSpecIndex_DigitalOcean_FullCheckoutLocalResolve(t *testing.T) {
@@ -263,7 +261,6 @@ func TestSpecIndex_DigitalOcean_FullCheckoutLocalResolve(t *testing.T) {
assert.Equal(t, int64(1330184), rolo.RolodexFileSize())
assert.Equal(t, "1.27 MB", rolo.RolodexFileSizeAsString())
assert.Equal(t, 1696, rolo.RolodexTotalFiles())
}
func TestSpecIndex_DigitalOcean_FullCheckoutLocalResolve_RecursiveLookup(t *testing.T) {
@@ -337,7 +334,6 @@ func TestSpecIndex_DigitalOcean_FullCheckoutLocalResolve_RecursiveLookup(t *test
assert.Equal(t, int64(1270079), rolo.RolodexFileSize())
assert.Equal(t, "1.21 MB", rolo.RolodexFileSizeAsString())
assert.Equal(t, 1682, rolo.RolodexTotalFiles())
}
func TestSpecIndex_DigitalOcean_LookupsNotAllowed(t *testing.T) {
@@ -390,7 +386,6 @@ func TestSpecIndex_DigitalOcean_LookupsNotAllowed(t *testing.T) {
}
func TestSpecIndex_BaseURLError(t *testing.T) {
do, _ := os.ReadFile("../test_specs/digitalocean.yaml")
var rootNode yaml.Node
_ = yaml.Unmarshal(do, &rootNode)
@@ -433,7 +428,6 @@ func TestSpecIndex_BaseURLError(t *testing.T) {
fileLen := len(files)
assert.Equal(t, 0, fileLen)
assert.GreaterOrEqual(t, len(remoteFS.GetErrors()), 200)
}
func TestSpecIndex_k8s(t *testing.T) {
@@ -530,7 +524,6 @@ func TestSpecIndex_PetstoreV3(t *testing.T) {
index.SetAbsolutePath("/rooty/rootster")
assert.Equal(t, "/rooty/rootster", index.GetSpecAbsolutePath())
}
var mappedRefs = 15
@@ -703,17 +696,14 @@ func TestSpecIndex_NoRoot(t *testing.T) {
}
func test_buildMixedRefServer() *httptest.Server {
bs, _ := os.ReadFile("../test_specs/burgershop.openapi.yaml")
return httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.Header().Set("Last-Modified", "Wed, 21 Oct 2015 07:28:00 GMT")
_, _ = rw.Write(bs)
}))
}
func TestSpecIndex_BurgerShopMixedRef(t *testing.T) {
// create a test server.
server := test_buildMixedRefServer()
defer server.Close()
@@ -793,10 +783,9 @@ func TestSpecIndex_BurgerShopMixedRef(t *testing.T) {
assert.Len(t, index.GetCircularReferences(), 0)
// get the size of the rolodex.
assert.Equal(t, int64(60232), rolo.RolodexFileSize()+int64(len(yml)))
assert.Equal(t, int64(60226), rolo.RolodexFileSize()+int64(len(yml)))
assert.Equal(t, "50.48 KB", rolo.RolodexFileSizeAsString())
assert.Equal(t, 3, rolo.RolodexTotalFiles())
}
func TestCalcSizeAsString(t *testing.T) {
@@ -1046,7 +1035,6 @@ paths:
}
func TestSpecIndex_lookupFileReference_MultiRes(t *testing.T) {
embie := []byte("naughty:\n - puppy: dog\n - puppy: naughty\npuppy:\n - naughty: puppy")
_ = os.WriteFile("embie.yaml", embie, 0o664)
@@ -1089,15 +1077,13 @@ func TestSpecIndex_lookupFileReference_MultiRes(t *testing.T) {
assert.NotNil(t, embieRoloFile)
index := rolo.GetRootIndex()
//index.seenRemoteSources = make(map[string]*yaml.Node)
// index.seenRemoteSources = make(map[string]*yaml.Node)
absoluteRef, _ := filepath.Abs("embie.yaml#/naughty")
fRef, _ := index.SearchIndexForReference(absoluteRef)
assert.NotNil(t, fRef)
}
func TestSpecIndex_lookupFileReference(t *testing.T) {
pup := []byte("good:\n - puppy: dog\n - puppy: forever-more")
var myPuppy yaml.Node
@@ -1138,11 +1124,9 @@ func TestSpecIndex_lookupFileReference(t *testing.T) {
assert.NoError(t, fErr)
assert.Equal(t, "fox.yaml", fox.Name())
assert.Equal(t, "good:\n - puppy: dog\n - puppy: forever-more", string(fox.GetContent()))
}
func TestSpecIndex_parameterReferencesHavePaths(t *testing.T) {
_ = os.WriteFile("paramour.yaml", []byte(`components:
parameters:
param3: