Skip to content

Commit f345637

Browse files
committed
fixup! add CopyInto method to schema.Schema
1 parent c26273c commit f345637

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

schema/elements_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,44 @@ func TestResolve(t *testing.T) {
120120
})
121121
}
122122
}
123+
124+
func TestCopyInto(t *testing.T) {
125+
existing := "existing"
126+
notExisting := "not-existing"
127+
a := Atom{List: &List{}}
128+
129+
tests := []struct {
130+
testName string
131+
schemaTypeDefs []TypeDef
132+
typeRef TypeRef
133+
}{
134+
{"noNamedType", nil, TypeRef{Inlined: a}},
135+
{"notExistingNamedType", nil, TypeRef{NamedType: &notExisting}},
136+
{"existingNamedType", []TypeDef{{Name: existing, Atom: a}}, TypeRef{NamedType: &existing}},
137+
}
138+
139+
for _, tt := range tests {
140+
t.Run(tt.testName, func(t *testing.T) {
141+
t.Parallel()
142+
s := Schema{
143+
Types: tt.schemaTypeDefs,
144+
}
145+
146+
theCopy := Schema{}
147+
s.CopyInto(&theCopy)
148+
149+
if !reflect.DeepEqual(s, theCopy) {
150+
t.Fatal("")
151+
}
152+
153+
// test after resolve
154+
_, _ = s.Resolve(tt.typeRef)
155+
theCopy = Schema{}
156+
s.CopyInto(&theCopy)
157+
158+
if !reflect.DeepEqual(s, theCopy) {
159+
t.Fatal("")
160+
}
161+
})
162+
}
163+
}

0 commit comments

Comments
 (0)