z_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package rest_gorm
  2. import (
  3. "reflect"
  4. "testing"
  5. "git.ali33.ru/fcg-xvii/rest"
  6. )
  7. type ExtSize struct {
  8. ID int
  9. }
  10. type NameExtChild struct {
  11. ID int
  12. Name string
  13. Size *ExtSize `rest:"ext"`
  14. }
  15. type NameExt struct {
  16. ID int
  17. Name string
  18. ExtPointer *NameExtChild `rest:"ext"`
  19. ExtSlice []NameExtChild `rest:"ext"`
  20. ExtStruct NameExtChild `rest:"ext"`
  21. }
  22. func TestNamesExt(t *testing.T) {
  23. //i := 10
  24. //r := reflect.ValueOf(&i)
  25. r := reflect.ValueOf(&NameExt{})
  26. //rType := reflect.TypeOf(r.Type())
  27. res, err := namesExt(r)
  28. if err != nil {
  29. t.Fatal(err)
  30. }
  31. for _, v := range res {
  32. t.Log(v.eName, reflect.ValueOf(v.eValue).Elem().Type())
  33. }
  34. t.Log(res)
  35. }
  36. func TestPreload(t *testing.T) {
  37. fields := rest.FieldList{
  38. &rest.Field{
  39. Name: "ExtStruct",
  40. Names: rest.FieldList{
  41. &rest.Field{
  42. Name: "Size",
  43. },
  44. },
  45. },
  46. &rest.Field{
  47. Name: "ExtSlice",
  48. },
  49. &rest.Field{
  50. Name: "ExtPointer",
  51. Names: rest.FieldList{
  52. &rest.Field{
  53. Name: "Size",
  54. },
  55. },
  56. },
  57. }
  58. val := &NameExt{}
  59. _, err := Preload(val, fields, nil)
  60. if err != nil {
  61. t.Fatal(err)
  62. }
  63. }