| giolekva | c76b21b | 2020-04-18 19:28:43 +0400 | [diff] [blame^] | 1 | package schema |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "log" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestInMemorySimple(t *testing.T) { |
| 10 | s := NewInMemorySchemaStore() |
| 11 | err := s.AddSchema(` |
| 12 | type M { |
| 13 | X: Int |
| 14 | }`) |
| 15 | if err != nil { |
| 16 | t.Fatal(err) |
| 17 | } |
| 18 | for _, def := range s.Schema().Definitions { |
| 19 | fmt.Printf("%s - %s\n", def.Name, def.Kind) |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | func TestInMemory(t *testing.T) { |
| 24 | s := NewInMemorySchemaStore() |
| 25 | err := s.AddSchema(` |
| 26 | type Image { |
| 27 | id: ID! |
| 28 | objectPath: String! |
| 29 | } |
| 30 | |
| 31 | type ImageSegment { |
| 32 | id: ID! @search |
| 33 | upperLeftX: Float! |
| 34 | upperLeftY: Float! |
| 35 | lowerRightX: Float! |
| 36 | lowerRightY: Float! |
| 37 | sourceImage: Image! |
| 38 | } |
| 39 | |
| 40 | extend type Image { |
| 41 | segments: [ImageSegment] |
| 42 | } |
| 43 | `) |
| 44 | if err != nil { |
| 45 | t.Fatal(err) |
| 46 | } |
| 47 | for _, def := range s.Schema().Definitions { |
| 48 | fmt.Printf("%s - %s\n", def.Name, def.Kind) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | func TestDgraph(t *testing.T) { |
| 53 | s, err := NewDgraphSchemaStore("http://localhost:8080/admin") |
| 54 | if err != nil { |
| 55 | t.Fatal(err) |
| 56 | } |
| 57 | if s.Schema() != nil { |
| 58 | for _, def := range s.Schema().Definitions { |
| 59 | fmt.Printf("%s - %s\n", def.Name, def.Kind) |
| 60 | } |
| 61 | } |
| 62 | err = s.AddSchema("type N { Y: ID! Z: Float }") |
| 63 | if err != nil { |
| 64 | t.Fatal(err) |
| 65 | } |
| 66 | if s.Schema() != nil { |
| 67 | for _, def := range s.Schema().Definitions { |
| 68 | fmt.Printf("%s - %s\n", def.Name, def.Kind) |
| 69 | } |
| 70 | } |
| 71 | log.Print("123123") |
| 72 | err = s.AddSchema("type M { X: Int }") |
| 73 | if err != nil { |
| 74 | t.Fatal(err) |
| 75 | } |
| 76 | if s.Schema() != nil { |
| 77 | for _, def := range s.Schema().Definitions { |
| 78 | fmt.Printf("%s - %s\n", def.Name, def.Kind) |
| 79 | } |
| 80 | } |
| 81 | } |