Files
libopenapi/datamodel/high/base/security_requirement_test.go
Dave Shanley 15e458fb5d Added more base components to mutable state.
Chopping through the list.
2023-03-26 06:10:31 -04:00

41 lines
914 B
Go

// 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"
"strings"
"testing"
)
func TestNewSecurityRequirement(t *testing.T) {
var cNode yaml.Node
yml := `pizza:
- cheese
- tomato`
_ = yaml.Unmarshal([]byte(yml), &cNode)
var lowExt lowbase.SecurityRequirement
_ = lowmodel.BuildModel(cNode.Content[0], &lowExt)
_ = lowExt.Build(cNode.Content[0], nil)
highExt := NewSecurityRequirement(&lowExt)
assert.Len(t, highExt.Requirements["pizza"], 2)
wentLow := highExt.GoLow()
assert.Len(t, wentLow.Requirements.Value, 1)
// render the high-level object as YAML
highBytes, _ := highExt.Render()
assert.Equal(t, strings.TrimSpace(string(highBytes)), yml)
}