mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 12:37:49 +00:00
Adding high base model tests
these were covered when used by v3 models, but need new tests when moved into a seperate package.
This commit is contained in:
41
datamodel/high/base/example_test.go
Normal file
41
datamodel/high/base/example_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package base
|
||||
|
||||
import (
|
||||
lowmodel "github.com/pb33f/libopenapi/datamodel/low"
|
||||
lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v3"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewExample(t *testing.T) {
|
||||
|
||||
var cNode yaml.Node
|
||||
|
||||
yml := `summary: an example
|
||||
description: something more
|
||||
value: a thing
|
||||
externalValue: https://pb33f.io
|
||||
x-hack: code`
|
||||
|
||||
_ = yaml.Unmarshal([]byte(yml), &cNode)
|
||||
|
||||
// build low
|
||||
var lowExample lowbase.Example
|
||||
_ = lowmodel.BuildModel(&cNode, &lowExample)
|
||||
|
||||
_ = lowExample.Build(cNode.Content[0], nil)
|
||||
|
||||
// build high
|
||||
highExample := NewExample(&lowExample)
|
||||
|
||||
assert.Equal(t, "an example", highExample.Summary)
|
||||
assert.Equal(t, "something more", highExample.Description)
|
||||
assert.Equal(t, "https://pb33f.io", highExample.ExternalValue)
|
||||
assert.Equal(t, "code", highExample.Extensions["x-hack"])
|
||||
assert.Equal(t, "a thing", highExample.Value)
|
||||
assert.Equal(t, 4, highExample.GoLow().ExternalValue.ValueNode.Line)
|
||||
}
|
||||
Reference in New Issue
Block a user