mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 20:47:44 +00:00
Refactored version directory names
3.0 and 2.0 do not work, there are multiple versions and anything with a period in it sucks from my point of view, v2 and v3 feel much better from a DX perspective.
This commit is contained in:
60
datamodel/low/v3/server_test.go
Normal file
60
datamodel/low/v3/server_test.go
Normal file
@@ -0,0 +1,60 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v3
|
||||
|
||||
import (
|
||||
"github.com/pb33f/libopenapi/datamodel/low"
|
||||
"github.com/pb33f/libopenapi/index"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v3"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestServer_Build(t *testing.T) {
|
||||
|
||||
yml := `url: https://pb33f.io
|
||||
description: high quality software for developers.
|
||||
variables:
|
||||
var1:
|
||||
default: hello
|
||||
description: a var
|
||||
enum: [one, two]`
|
||||
|
||||
var idxNode yaml.Node
|
||||
_ = yaml.Unmarshal([]byte(yml), &idxNode)
|
||||
idx := index.NewSpecIndex(&idxNode)
|
||||
|
||||
var n Server
|
||||
err := low.BuildModel(&idxNode, &n)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = n.Build(idxNode.Content[0], idx)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "https://pb33f.io", n.URL.Value)
|
||||
assert.Equal(t, "high quality software for developers.", n.Description.Value)
|
||||
assert.Equal(t, "hello", n.FindVariable("var1").Value.Default.Value)
|
||||
assert.Equal(t, "a var", n.FindVariable("var1").Value.Description.Value)
|
||||
|
||||
}
|
||||
|
||||
func TestServer_Build_NoVars(t *testing.T) {
|
||||
|
||||
yml := `url: https://pb33f.io
|
||||
description: high quality software for developers.`
|
||||
|
||||
var idxNode yaml.Node
|
||||
_ = yaml.Unmarshal([]byte(yml), &idxNode)
|
||||
idx := index.NewSpecIndex(&idxNode)
|
||||
|
||||
var n Server
|
||||
err := low.BuildModel(&idxNode, &n)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = n.Build(idxNode.Content[0], idx)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "https://pb33f.io", n.URL.Value)
|
||||
assert.Equal(t, "high quality software for developers.", n.Description.Value)
|
||||
assert.Len(t, n.Variables.Value, 0)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user