forked from ogen-go/ogen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec_test.go
53 lines (44 loc) · 1.13 KB
/
spec_test.go
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
50
51
52
53
package ogen_test
import (
"reflect"
"testing"
"github.com/go-faster/yaml"
"github.com/stretchr/testify/require"
"github.com/ogen-go/ogen"
)
func TestExtensionParsing(t *testing.T) {
a := require.New(t)
{
var (
input = `{"url": "/api/v1", "x-ogen-name": "foo"}`
s ogen.Server
)
a.NoError(yaml.Unmarshal([]byte(input), &s))
a.Equal("foo", s.Common.Extensions["x-ogen-name"].Value)
// FIXME(tdakkota): encodeDecode doesn't work for this type
}
{
var (
input = `{"description": "foo", "x-ogen-extension": "bar"}`
s ogen.Response
)
a.NoError(yaml.Unmarshal([]byte(input), &s))
a.Equal("bar", s.Common.Extensions["x-ogen-extension"].Value)
// FIXME(tdakkota): encodeDecode doesn't work for this type
}
}
func TestComponents_Init(t *testing.T) {
a := require.New(t)
c := ogen.Components{}
c.Init()
val := reflect.ValueOf(c)
a.Equalf(10+1, val.NumField(), "update this test if you add new fields to Components")
for i := 0; i < val.NumField(); i++ {
f := val.Field(i)
// Init doesn't set Common and it's ok.
if val.Type().Field(i).Name == "Common" {
continue
}
a.NotNil(f.Interface())
}
}