gopkg.in/rethinkdb/rethinkdb-go.v6@v6.2.2/internal/integration/tests/testdata_test.go (about) 1 package tests 2 3 import ( 4 r "gopkg.in/rethinkdb/rethinkdb-go.v6" 5 ) 6 7 func setupTestData() { 8 if *testdata { 9 // Delete any preexisting databases 10 r.DBDrop("test").Exec(session) 11 r.DBDrop("examples").Exec(session) 12 r.DBDrop("superheroes").Exec(session) 13 14 r.DBCreate("test").Exec(session) 15 r.DBCreate("examples").Exec(session) 16 17 r.DB("test").TableCreate("test").Exec(session) 18 r.DB("test").TableCreate("test2").Exec(session) 19 r.DB("test").TableCreate("changes").Exec(session) 20 21 r.DB("examples").TableCreate("posts").Exec(session) 22 r.DB("examples").TableCreate("heroes").Exec(session) 23 r.DB("examples").TableCreate("users").Exec(session) 24 r.DB("examples").TableCreate("games").Exec(session) 25 r.DB("examples").TableCreate("games2").Exec(session) 26 r.DB("examples").TableCreate("marvel").Exec(session) 27 28 r.DB("examples").Table("posts").IndexCreate("date").Exec(session) 29 r.DB("examples").Table("posts").IndexWait().Exec(session) 30 r.DB("examples").Table("posts").IndexCreateFunc( 31 "dateAndTitle", 32 []interface{}{r.Row.Field("date"), r.Row.Field("title")}, 33 ).Exec(session) 34 35 r.DB("examples").Table("heroes").IndexCreate("code_name").Exec(session) 36 r.DB("examples").Table("heroes").IndexWait().Exec(session) 37 38 r.DB("examples").Table("games").IndexCreate("type").Exec(session) 39 r.DB("examples").Table("games").IndexWait().Exec(session) 40 41 // Create heroes table 42 r.DB("examples").Table("heroes").Insert([]interface{}{ 43 map[string]interface{}{ 44 "id": 1, 45 "code_name": "batman", 46 "name": "Batman", 47 }, 48 map[string]interface{}{ 49 "id": 2, 50 "code_name": "man_of_steel", 51 "name": "Superman", 52 }, 53 map[string]interface{}{ 54 "id": 3, 55 "code_name": "ant_man", 56 "name": "Ant Man", 57 }, 58 map[string]interface{}{ 59 "id": 4, 60 "code_name": "flash", 61 "name": "The Flash", 62 }, 63 }).Exec(session) 64 65 // Create users table 66 r.DB("examples").Table("users").Insert([]interface{}{ 67 map[string]interface{}{ 68 "id": "william", 69 "email": "william@rethinkdb.com", 70 "age": 30, 71 }, 72 map[string]interface{}{ 73 "id": "lara", 74 "email": "lara@rethinkdb.com", 75 "age": 30, 76 }, 77 map[string]interface{}{ 78 "id": "john", 79 "email": "john@rethinkdb.com", 80 "age": 19, 81 }, 82 map[string]interface{}{ 83 "id": "jane", 84 "email": "jane@rethinkdb.com", 85 "age": 45, 86 }, 87 map[string]interface{}{ 88 "id": "bob", 89 "email": "bob@rethinkdb.com", 90 "age": 24, 91 }, 92 map[string]interface{}{ 93 "id": "brad", 94 "email": "brad@gmail.com", 95 "age": 15, 96 }, 97 }).Exec(session) 98 99 // Create games table 100 r.DB("examples").Table("games").Insert([]interface{}{ 101 map[string]interface{}{"id": 2, "player": "Bob", "points": 15, "type": "ranked"}, 102 map[string]interface{}{"id": 5, "player": "Alice", "points": 7, "type": "free"}, 103 map[string]interface{}{"id": 11, "player": "Bob", "points": 10, "type": "free"}, 104 map[string]interface{}{"id": 12, "player": "Alice", "points": 2, "type": "free"}, 105 }).Exec(session) 106 107 // Create games2 table 108 r.DB("examples").Table("games2").Insert([]interface{}{ 109 map[string]interface{}{"id": 1, "matches": map[string]interface{}{"a": []int{1, 2, 3}, "b": []int{4, 5, 6}}}, 110 map[string]interface{}{"id": 2, "matches": map[string]interface{}{"b": []int{100}, "c": []int{7, 8, 9}}}, 111 map[string]interface{}{"id": 3, "matches": map[string]interface{}{"a": []int{10, 20}, "c": []int{70, 80}}}, 112 }).Exec(session) 113 114 // Create marvel table 115 r.DB("examples").Table("marvel").Insert([]interface{}{ 116 map[string]interface{}{"name": "Iron Man", "victories": 214}, 117 map[string]interface{}{"name": "Jubilee", "victories": 9}, 118 }).Exec(session) 119 } 120 }