mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 20:47:49 +00:00
Working on building out models
a recursive approach? or a dfs approach? not sure yet. still playing with ideas.
This commit is contained in:
51
utils/model_builder_test.go
Normal file
51
utils/model_builder_test.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v3"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type spank[t any] struct {
|
||||
life t
|
||||
}
|
||||
|
||||
type hotdog struct {
|
||||
Name string
|
||||
Beef bool
|
||||
Fat int
|
||||
Ketchup float32
|
||||
Mustard float64
|
||||
Grilled spank[bool]
|
||||
NotGrilled spank[string]
|
||||
}
|
||||
|
||||
func (h hotdog) Build(node *yaml.Node) {
|
||||
|
||||
}
|
||||
|
||||
func TestBuildModel(t *testing.T) {
|
||||
|
||||
yml := `name: yummy
|
||||
beef: true
|
||||
fat: 200
|
||||
ketchup: 200.45
|
||||
mustard: 324938249028.98234892374892374923874823974
|
||||
grilled: false
|
||||
notGrilled: false`
|
||||
|
||||
var rootNode yaml.Node
|
||||
mErr := yaml.Unmarshal([]byte(yml), &rootNode)
|
||||
assert.NoError(t, mErr)
|
||||
|
||||
hd := hotdog{}
|
||||
cErr := BuildModel(&rootNode, &hd)
|
||||
assert.Equal(t, 200, hd.Fat)
|
||||
assert.Equal(t, true, hd.Beef)
|
||||
assert.Equal(t, "yummy", hd.Name)
|
||||
assert.Equal(t, float32(200.45), hd.Ketchup)
|
||||
assert.Equal(t, 324938249028.98234892374892374923874823974, hd.Mustard)
|
||||
|
||||
assert.NoError(t, cErr)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user