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

Function TestEdgeCases

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

Source from the content-addressed store, hash-verified

1051}
1052
1053func TestEdgeCases(t *testing.T) {
1054 t.Parallel()
1055
1056 t.Run("set at pointer against an unsupported type (int) should error", func(t *testing.T) {
1057 p, err := New("/invalid")
1058 require.NoError(t, err)
1059 _, err = p.Set(1, 1234)
1060 require.Error(t, err)
1061 require.ErrorIs(t, err, ErrUnsupportedValueType)
1062 })
1063
1064 t.Run("set with empty pointer", func(t *testing.T) {
1065 p, err := New("")
1066 require.NoError(t, err)
1067
1068 doc := testDocumentJSON(t)
1069 newDoc, err := p.Set(doc, 1)
1070 require.NoError(t, err)
1071
1072 require.Equal(t, doc, newDoc)
1073 })
1074
1075 t.Run("with out of bounds index", func(t *testing.T) {
1076 p, err := New("/foo/10")
1077 require.NoError(t, err)
1078
1079 t.Run("should error on Get", func(t *testing.T) {
1080 _, _, err := p.Get(testStructJSONDoc(t))
1081 require.Error(t, err)
1082 require.ErrorContains(t, err, "index out of bounds")
1083 })
1084
1085 t.Run("should error on Set", func(t *testing.T) {
1086 _, err := p.Set(testStructJSONPtr(t), "peek-a-boo")
1087 require.Error(t, err)
1088 require.ErrorContains(t, err, "index out of bounds")
1089 })
1090 })
1091
1092 t.Run("Set with invalid pointer token", func(t *testing.T) {
1093 doc := testStructJSONDoc(t)
1094 pointer, err := New("/foo/x")
1095 require.NoError(t, err)
1096
1097 _, err = pointer.Set(&doc, "yay")
1098 require.Error(t, err)
1099 require.ErrorContains(t, err, `Atoi: parsing "x"`)
1100 })
1101
1102 t.Run("Set with invalid reference in struct", func(t *testing.T) {
1103 doc := struct {
1104 A func() `json:"a"`
1105 B []int `json:"b"`
1106 }{
1107 A: func() {},
1108 B: []int{0, 1},
1109 }
1110

Callers

nothing calls this directly

Calls 7

NewFunction · 0.85
testDocumentJSONFunction · 0.85
testStructJSONDocFunction · 0.85
testStructJSONPtrFunction · 0.85
SetMethod · 0.80
ErrorMethod · 0.80
GetMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…