| 129 | } |
| 130 | |
| 131 | func TestRecursiveStructures(t *testing.T) { |
| 132 | t.Parallel() |
| 133 | |
| 134 | recursiveStruct := &structpb.Struct{Fields: make(map[string]*structpb.Value)} |
| 135 | recursiveStruct.Fields["test"] = &structpb.Value{ |
| 136 | Kind: &structpb.Value_StructValue{ |
| 137 | StructValue: recursiveStruct, |
| 138 | }, |
| 139 | } |
| 140 | recursiveList := &structpb.ListValue{Values: make([]*structpb.Value, 1)} |
| 141 | recursiveList.Values[0] = &structpb.Value{ |
| 142 | Kind: &structpb.Value_ListValue{ |
| 143 | ListValue: recursiveList, |
| 144 | }, |
| 145 | } |
| 146 | recursiveValueStruct := &structpb.Value{ |
| 147 | Kind: &structpb.Value_StructValue{ |
| 148 | StructValue: recursiveStruct, |
| 149 | }, |
| 150 | } |
| 151 | recursiveValueList := &structpb.Value{ |
| 152 | Kind: &structpb.Value_ListValue{ |
| 153 | ListValue: recursiveList, |
| 154 | }, |
| 155 | } |
| 156 | |
| 157 | recursiveMap := make(map[string]any) |
| 158 | recursiveMap["test"] = recursiveMap |
| 159 | recursiveSlice := make([]any, 1) |
| 160 | recursiveSlice[0] = recursiveSlice |
| 161 | type recursiveGoStruct struct { |
| 162 | self *recursiveGoStruct |
| 163 | } |
| 164 | recursiveGoStructValue := &recursiveGoStruct{} |
| 165 | recursiveGoStructValue.self = recursiveGoStructValue |
| 166 | |
| 167 | t.Run("Map", func(t *testing.T) { |
| 168 | t.Parallel() |
| 169 | |
| 170 | a := assertions.New(t) |
| 171 | _, err := goproto.Map(recursiveStruct) |
| 172 | a.So(err, should.NotBeNil) |
| 173 | }) |
| 174 | |
| 175 | t.Run("Slice", func(t *testing.T) { |
| 176 | t.Parallel() |
| 177 | |
| 178 | a := assertions.New(t) |
| 179 | _, err := goproto.Slice(recursiveList) |
| 180 | a.So(err, should.NotBeNil) |
| 181 | }) |
| 182 | |
| 183 | t.Run("Interface", func(t *testing.T) { |
| 184 | t.Parallel() |
| 185 | |
| 186 | a := assertions.New(t) |
| 187 | _, err := goproto.Interface(recursiveValueStruct) |
| 188 | a.So(err, should.NotBeNil) |