mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 04:20:11 +00:00
37 lines
972 B
Go
37 lines
972 B
Go
// Copyright 2023 Princess B33f Heavy Industries / Dave Shanley
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package index
|
|
|
|
import (
|
|
"context"
|
|
"github.com/stretchr/testify/assert"
|
|
"gopkg.in/yaml.v3"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestSpecIndex_SearchIndexForReference(t *testing.T) {
|
|
petstore, _ := os.ReadFile("../test_specs/petstorev3.json")
|
|
var rootNode yaml.Node
|
|
_ = yaml.Unmarshal(petstore, &rootNode)
|
|
|
|
c := CreateOpenAPIIndexConfig()
|
|
idx := NewSpecIndexWithConfig(&rootNode, c)
|
|
|
|
ref, _ := idx.SearchIndexForReference("#/components/schemas/Pet")
|
|
assert.NotNil(t, ref)
|
|
}
|
|
|
|
func TestSpecIndex_SearchIndexForReferenceWithContext(t *testing.T) {
|
|
petstore, _ := os.ReadFile("../test_specs/petstorev3.json")
|
|
var rootNode yaml.Node
|
|
_ = yaml.Unmarshal(petstore, &rootNode)
|
|
|
|
c := CreateOpenAPIIndexConfig()
|
|
idx := NewSpecIndexWithConfig(&rootNode, c)
|
|
|
|
ref, _, _ := idx.SearchIndexForReferenceWithContext(context.Background(), "#/components/schemas/Pet")
|
|
assert.NotNil(t, ref)
|
|
}
|