Skip to content

Commit 1fce0a0

Browse files
author
jennybuckley
committed
Use inlined typeref instead of schema
1 parent 8f9bdaf commit 1fce0a0

File tree

2 files changed

+36
-52
lines changed

2 files changed

+36
-52
lines changed

schema/fromvalue.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,11 @@ import (
2020
"sigs.k8s.io/structured-merge-diff/value"
2121
)
2222

23-
// FromValue creates a schema from a value v
24-
func FromValue(name string, v value.Value) *Schema {
23+
// TypeRefFromValue creates an inlined type from a value v
24+
func TypeRefFromValue(v value.Value) TypeRef {
2525
atom := atomFor(v)
26-
typeDef := TypeDef{
27-
Name: name,
28-
Atom: atom,
29-
}
30-
return &Schema{
31-
Types: []TypeDef{typeDef},
26+
return TypeRef{
27+
Inlined: atom,
3228
}
3329
}
3430

schema/fromvalue_test.go

Lines changed: 32 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,55 +25,43 @@ import (
2525
"sigs.k8s.io/structured-merge-diff/value"
2626
)
2727

28-
const (
29-
typeName = "test"
30-
)
31-
32-
func TestFromValue(t *testing.T) {
28+
func TestTypeRefFromValue(t *testing.T) {
3329

3430
table := []struct {
3531
objYAML string
36-
schema string
32+
typeRef string
3733
}{
3834
{`a: a`, `
39-
types:
40-
- name: ` + typeName + `
41-
struct:
42-
fields:
43-
- name: a
44-
type:
45-
untyped: {}`},
35+
struct:
36+
fields:
37+
- name: a
38+
type:
39+
untyped: {}`},
4640
{`{"a": [{"a": null}]}`, `
47-
types:
48-
- name: ` + typeName + `
49-
struct:
50-
fields:
51-
- name: a
52-
type:
53-
untyped: {}`},
41+
struct:
42+
fields:
43+
- name: a
44+
type:
45+
untyped: {}`},
5446
{`{"a": null}`, `
55-
types:
56-
- name: ` + typeName + `
57-
struct:
58-
fields:
59-
- name: a
60-
type:
61-
untyped: {}`},
47+
struct:
48+
fields:
49+
- name: a
50+
type:
51+
untyped: {}`},
6252
{`{"q": {"y": 6, "b": [7, 8, 9]}}`, `
63-
types:
64-
- name: ` + typeName + `
65-
struct:
66-
fields:
67-
- name: q
68-
type:
69-
struct:
70-
fields:
71-
- name: y
72-
type:
73-
untyped: {}
74-
- name: b
75-
type:
76-
untyped: {}`},
53+
struct:
54+
fields:
55+
- name: q
56+
type:
57+
struct:
58+
fields:
59+
- name: y
60+
type:
61+
untyped: {}
62+
- name: b
63+
type:
64+
untyped: {}`},
7765
}
7866

7967
for _, tt := range table {
@@ -84,10 +72,10 @@ types:
8472
if err != nil {
8573
t.Fatalf("couldn't parse: %v", err)
8674
}
87-
got := schema.FromValue(typeName, v)
75+
got := schema.TypeRefFromValue(v)
8876

89-
expected := &schema.Schema{}
90-
err = yaml.Unmarshal([]byte(tt.schema), expected)
77+
expected := schema.TypeRef{}
78+
err = yaml.Unmarshal([]byte(tt.typeRef), &expected)
9179
if err != nil {
9280
t.Fatalf("couldn't parse: %v", err)
9381
}

0 commit comments

Comments
 (0)