-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathextensions_test.go
More file actions
49 lines (40 loc) · 1.5 KB
/
extensions_test.go
File metadata and controls
49 lines (40 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package core_test
import (
"context"
"testing"
"github.com/speakeasy-api/openapi/extensions/core"
"github.com/speakeasy-api/openapi/internal/interfaces"
"github.com/speakeasy-api/openapi/internal/testutils"
"github.com/speakeasy-api/openapi/marshaller"
"github.com/speakeasy-api/openapi/sequencedmap"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.yaml.in/yaml/v4"
)
type TestCoreModel struct {
marshaller.CoreModel `model:"testCoreModel"`
Name marshaller.Node[string] `key:"name"`
Value marshaller.Node[*yaml.Node] `key:"value" required:"true"`
}
var _ interfaces.CoreModel = (*TestCoreModel)(nil)
func (t *TestCoreModel) Unmarshal(ctx context.Context, parentName string, node *yaml.Node) ([]error, error) {
return marshaller.UnmarshalModel(ctx, node, t)
}
func TestUnmarshalExtensionModel_Success(t *testing.T) {
t.Parallel()
e := sequencedmap.New(
sequencedmap.NewElem("x-speakeasy-test", marshaller.Node[*yaml.Node]{
Value: testutils.CreateMapYamlNode([]*yaml.Node{
testutils.CreateStringYamlNode("name", 0, 0),
testutils.CreateStringYamlNode("test", 0, 0),
testutils.CreateStringYamlNode("value", 0, 0),
testutils.CreateIntYamlNode(1, 0, 0),
}, 0, 0),
}),
)
tcm, validationErrs, err := core.UnmarshalExtensionModel[TestCoreModel](t.Context(), e, "x-speakeasy-test")
require.NoError(t, err)
require.Empty(t, validationErrs)
assert.Equal(t, "test", tcm.Name.Value)
assert.Equal(t, testutils.CreateIntYamlNode(1, 0, 0), tcm.Value.Value)
}