MCPcopy Index your code
hub / github.com/go-openapi/jsonpointer / TestInternalEdgeCases

Function TestInternalEdgeCases

pointer_test.go:1144–1180  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1142}
1143
1144func TestInternalEdgeCases(t *testing.T) {
1145 t.Parallel()
1146
1147 t.Run("setSingleImpl should error on any node not a struct, map or slice", func(t *testing.T) {
1148 var node int
1149
1150 _, err := setSingleImpl(&node, 3, "a", jsonname.DefaultJSONNameProvider)
1151 require.Error(t, err)
1152 require.ErrorContains(t, err, `invalid token reference "a"`)
1153 })
1154
1155 t.Run("with simulated unsettable", func(t *testing.T) {
1156 type unsettable struct {
1157 A string `json:"a"`
1158 }
1159 doc := unsettable{
1160 A: "a",
1161 }
1162
1163 t.Run("setSingleImpl should error on struct field that is not settable", func(t *testing.T) {
1164 node := doc // doesn't pass a pointer: unsettable
1165
1166 _, err := setSingleImpl(node, "new value", "a", jsonname.DefaultJSONNameProvider)
1167 require.Error(t, err)
1168 require.ErrorContains(t, err, `can't set struct field`)
1169 })
1170 })
1171
1172 t.Run("assignReflectValue is a no-op when src is an untyped nil", func(t *testing.T) {
1173 target := "unchanged"
1174 dst := reflect.ValueOf(&target).Elem()
1175
1176 assignReflectValue(dst, nil)
1177
1178 require.Equal(t, "unchanged", target)
1179 })
1180}
1181
1182func TestSetIntermediateErrors(t *testing.T) {
1183 t.Parallel()

Callers

nothing calls this directly

Calls 3

setSingleImplFunction · 0.85
assignReflectValueFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…