-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathvalue_test.go
More file actions
99 lines (91 loc) · 2.14 KB
/
value_test.go
File metadata and controls
99 lines (91 loc) · 2.14 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package expression_test
import (
"testing"
"github.com/speakeasy-api/openapi/expression"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.yaml.in/yaml/v4"
)
func TestGetValueOrExpressionValue_Success(t *testing.T) {
t.Parallel()
tests := []struct {
name string
value *yaml.Node
expectValue bool
expectExpr bool
expectNil bool
expectedString string
}{
{
name: "nil value returns nil",
value: nil,
expectNil: true,
expectExpr: false,
},
{
name: "expression string returns expression",
value: &yaml.Node{Kind: yaml.ScalarNode, Value: "$url"},
expectExpr: true,
expectValue: false,
},
{
name: "non-expression string returns value",
value: &yaml.Node{Kind: yaml.ScalarNode, Value: "plain string"},
expectExpr: false,
expectValue: true,
},
{
name: "integer returns value",
value: &yaml.Node{Kind: yaml.ScalarNode, Value: "42", Tag: "!!int"},
expectExpr: false,
expectValue: true,
},
{
name: "boolean returns value",
value: &yaml.Node{Kind: yaml.ScalarNode, Value: "true", Tag: "!!bool"},
expectExpr: false,
expectValue: true,
},
{
name: "map node returns value",
value: &yaml.Node{
Kind: yaml.MappingNode,
Content: []*yaml.Node{
{Kind: yaml.ScalarNode, Value: "key"},
{Kind: yaml.ScalarNode, Value: "val"},
},
},
expectExpr: false,
expectValue: true,
},
{
name: "sequence node returns value",
value: &yaml.Node{
Kind: yaml.SequenceNode,
Content: []*yaml.Node{
{Kind: yaml.ScalarNode, Value: "item1"},
},
},
expectExpr: false,
expectValue: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
value, expr, err := expression.GetValueOrExpressionValue(tt.value)
require.NoError(t, err)
switch {
case tt.expectNil:
assert.Nil(t, value)
assert.Nil(t, expr)
case tt.expectExpr:
assert.Nil(t, value)
assert.NotNil(t, expr)
case tt.expectValue:
assert.NotNil(t, value)
assert.Nil(t, expr)
}
})
}
}