mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 20:47:44 +00:00
All tests in index and datamodel now pass. The rolodex fixes all the things. Signed-off-by: quobix <dave@quobix.com>
114 lines
2.3 KiB
Go
114 lines
2.3 KiB
Go
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package v2
|
|
|
|
import (
|
|
"context"
|
|
"github.com/pb33f/libopenapi/datamodel/low"
|
|
"github.com/pb33f/libopenapi/index"
|
|
"github.com/stretchr/testify/assert"
|
|
"gopkg.in/yaml.v3"
|
|
"testing"
|
|
)
|
|
|
|
func TestPathItem_Build_Params(t *testing.T) {
|
|
|
|
yml := `parameters:
|
|
$ref: break`
|
|
|
|
var idxNode yaml.Node
|
|
mErr := yaml.Unmarshal([]byte(yml), &idxNode)
|
|
assert.NoError(t, mErr)
|
|
idx := index.NewSpecIndex(&idxNode)
|
|
|
|
var n PathItem
|
|
err := low.BuildModel(&idxNode, &n)
|
|
assert.NoError(t, err)
|
|
|
|
err = n.Build(context.Background(), nil, idxNode.Content[0], idx)
|
|
assert.Error(t, err)
|
|
|
|
}
|
|
|
|
func TestPathItem_Build_MethodFail(t *testing.T) {
|
|
|
|
yml := `post:
|
|
$ref: break`
|
|
|
|
var idxNode yaml.Node
|
|
mErr := yaml.Unmarshal([]byte(yml), &idxNode)
|
|
assert.NoError(t, mErr)
|
|
idx := index.NewSpecIndex(&idxNode)
|
|
|
|
var n PathItem
|
|
err := low.BuildModel(&idxNode, &n)
|
|
assert.NoError(t, err)
|
|
|
|
err = n.Build(context.Background(), nil, idxNode.Content[0], idx)
|
|
assert.Error(t, err)
|
|
|
|
}
|
|
|
|
func TestPathItem_Hash(t *testing.T) {
|
|
|
|
yml := `get:
|
|
description: get me up
|
|
put:
|
|
description: put me out
|
|
post:
|
|
description: post me there
|
|
delete:
|
|
description: delete me please
|
|
options:
|
|
description: whats on the menu
|
|
parameters:
|
|
- name: fishy
|
|
location: sea
|
|
head:
|
|
description: meta me up
|
|
patch:
|
|
description: I got a boo boo
|
|
x-winter: is coming`
|
|
|
|
var idxNode yaml.Node
|
|
_ = yaml.Unmarshal([]byte(yml), &idxNode)
|
|
idx := index.NewSpecIndex(&idxNode)
|
|
|
|
var n PathItem
|
|
_ = low.BuildModel(idxNode.Content[0], &n)
|
|
_ = n.Build(context.Background(), nil, idxNode.Content[0], idx)
|
|
|
|
yml2 := `post:
|
|
description: post me there
|
|
put:
|
|
description: put me out
|
|
delete:
|
|
description: delete me please
|
|
options:
|
|
description: whats on the menu
|
|
patch:
|
|
description: I got a boo boo
|
|
head:
|
|
description: meta me up
|
|
x-winter: is coming
|
|
get:
|
|
description: get me up
|
|
parameters:
|
|
- name: fishy
|
|
location: sea`
|
|
|
|
var idxNode2 yaml.Node
|
|
_ = yaml.Unmarshal([]byte(yml2), &idxNode2)
|
|
idx2 := index.NewSpecIndex(&idxNode2)
|
|
|
|
var n2 PathItem
|
|
_ = low.BuildModel(idxNode2.Content[0], &n2)
|
|
_ = n2.Build(context.Background(), nil, idxNode2.Content[0], idx2)
|
|
|
|
// hash
|
|
assert.Equal(t, n.Hash(), n2.Hash())
|
|
assert.Len(t, n.GetExtensions(), 1)
|
|
|
|
}
|