コード例 #1
0
ファイル: geo_test.go プロジェクト: dgraph-io/dgraph
func TestIntersectsPolygon2(t *testing.T) {
	dir, ps := createTestStore(t)
	defer os.RemoveAll(dir)
	defer ps.Close()

	createTestData(t, ps)
	gq := &gql.GraphQuery{
		Alias: "me",
		Func: &gql.Function{
			Attr: "geometry",
			Name: "intersects",
			Args: []string{
				`{"Type":"Polygon",	"Coordinates":[[[-121.6, 37.1], [-122.4, 37.3], 
					[-122.6, 37.8], [-122.5, 38.3], [-121.9, 38], [-121.6, 37.1]]]}`,
			},
		},
		Children: []*gql.GraphQuery{&gql.GraphQuery{Attr: "name"}},
	}

	mp := runQuery(t, gq)
	expected := `{"me":[{"name":"Googleplex"},{"name":"Shoreline Amphitheater"},
			{"name":"San Carlos Airport"},{"name":"SF Bay area"},
			{"name":"Mountain View"},{"name":"San Carlos"}]}`
	require.JSONEq(t, expected, mp)
}
コード例 #2
0
ファイル: node_test.go プロジェクト: prometheus/prometheus
func requireTargetGroups(t *testing.T, expected, res []*config.TargetGroup) {
	b1, err := json.Marshal(expected)
	if err != nil {
		panic(err)
	}
	b2, err := json.Marshal(res)
	if err != nil {
		panic(err)
	}

	require.JSONEq(t, string(b1), string(b2))
}
コード例 #3
0
ファイル: query_test.go プロジェクト: dgraph-io/dgraph
func TestContainsGenerator(t *testing.T) {
	dir1, dir2, _ := populateGraph(t)
	defer os.RemoveAll(dir1)
	defer os.RemoveAll(dir2)
	query := `{
		me(contains("loc",  "{'Type':'Point', 'Coordinates':[2.0, 0.0]}")) {
			name
		}
	}`

	js := processToJSON(t, query)
	require.JSONEq(t, `{"me":[{"name":"Rick Grimes"}]}`, string(js))
}
コード例 #4
0
ファイル: query_test.go プロジェクト: dgraph-io/dgraph
func TestIntersectsGenerator(t *testing.T) {
	dir1, dir2, _ := populateGraph(t)
	defer os.RemoveAll(dir1)
	defer os.RemoveAll(dir2)
	query := `{
		me(intersects("loc", "{'Type':'Polygon', 'Coordinates':[[[0.0,0.0], [2.0,0.0], [1.5, 3.0], [0.0, 2.0]]]}")) {
			name
		}
	}`

	js := processToJSON(t, query)
	require.JSONEq(t, `{"me":[{"name":"Michonne"}, {"name":"Rick Grimes"}]}`, string(js))
}
コード例 #5
0
ファイル: query_test.go プロジェクト: dgraph-io/dgraph
func TestGeneratorMultiRoot(t *testing.T) {
	dir1, dir2, _ := populateGraph(t)
	defer os.RemoveAll(dir1)
	defer os.RemoveAll(dir2)
	query := `
    {
      me(anyof("name", "Michonne Rick Glenn")) {
        name
      }
    }
  `
	js := processToJSON(t, query)
	require.JSONEq(t, `{"me":[{"name":"Michonne"},{"name":"Rick Grimes"},{"name":"Glenn Rhee"}]}`, js)
}
コード例 #6
0
ファイル: query_test.go プロジェクト: dgraph-io/dgraph
func TestNearGenerator(t *testing.T) {
	dir1, dir2, _ := populateGraph(t)
	defer os.RemoveAll(dir1)
	defer os.RemoveAll(dir2)
	query := `{
		me(near("loc", "{'Type':'Point', 'Coordinates':[1.1,2.0]}", "5")) {
			name
			gender
		}
	}`

	js := processToJSON(t, query)
	require.JSONEq(t, `{"me":[{"gender":"female","name":"Michonne"}]}`, string(js))
}
コード例 #7
0
ファイル: query_test.go プロジェクト: dgraph-io/dgraph
func TestGenerator(t *testing.T) {
	dir1, dir2, _ := populateGraph(t)
	defer os.RemoveAll(dir1)
	defer os.RemoveAll(dir2)
	query := `
    {
      me(anyof("name", "Michonne")) {
        name
        gender
      }
    }
  `
	js := processToJSON(t, query)
	require.JSONEq(t, `{"me":[{"gender":"female","name":"Michonne"}]}`, js)
}
コード例 #8
0
ファイル: geo_test.go プロジェクト: dgraph-io/dgraph
func TestContainsPoint(t *testing.T) {
	dir, ps := createTestStore(t)
	defer os.RemoveAll(dir)
	defer ps.Close()

	createTestData(t, ps)
	gq := &gql.GraphQuery{
		Alias: "me",
		Func: &gql.Function{Attr: "geometry", Name: "contains", Args: []string{
			`{"Type":"Point", "Coordinates":[-122.082506, 37.4249518]}`},
		},
		Children: []*gql.GraphQuery{&gql.GraphQuery{Attr: "name"}},
	}

	mp := runQuery(t, gq)
	expected := `{"me":[{"name":"SF Bay area"},{"name":"Mountain View"}]}`
	require.JSONEq(t, expected, mp)
}
コード例 #9
0
ファイル: geo_test.go プロジェクト: dgraph-io/dgraph
func TestNearPoint(t *testing.T) {
	dir, ps := createTestStore(t)
	defer os.RemoveAll(dir)
	defer ps.Close()

	createTestData(t, ps)
	gq := &gql.GraphQuery{
		Alias: "me",
		Func: &gql.Function{
			Attr: "geometry",
			Name: "near",
			Args: []string{`{"Type":"Point", "Coordinates":[-122.082506, 37.4249518]}`, "1000"},
		},
		Children: []*gql.GraphQuery{&gql.GraphQuery{Attr: "name"}},
	}

	mp := runQuery(t, gq)
	expected := `{"me":[{"name":"Googleplex"},{"name":"Shoreline Amphitheater"}]}`
	require.JSONEq(t, expected, mp)
}
コード例 #10
0
ファイル: geo_test.go プロジェクト: dgraph-io/dgraph
func TestWithinPolygon(t *testing.T) {
	dir, ps := createTestStore(t)
	defer os.RemoveAll(dir)
	defer ps.Close()

	createTestData(t, ps)

	gq := &gql.GraphQuery{
		Alias: "me",
		Func: &gql.Function{Attr: "geometry", Name: "within", Args: []string{
			`{"Type":"Polygon", "Coordinates":[[[-122.06, 37.37], [-122.1, 37.36], 
			[-122.12, 37.4], [-122.11, 37.43], [-122.04, 37.43], [-122.06, 37.37]]]}`},
		},
		Children: []*gql.GraphQuery{&gql.GraphQuery{Attr: "name"}},
	}

	mp := runQuery(t, gq)
	expected := `{"me":[{"name":"Googleplex"},{"name":"Shoreline Amphitheater"}]}`
	require.JSONEq(t, expected, mp)
}
コード例 #11
0
ファイル: query_test.go プロジェクト: dgraph-io/dgraph
func TestToJSONFilterGeqNoResult(t *testing.T) {
	dir, dir2, _ := populateGraph(t)
	defer os.RemoveAll(dir)
	defer os.RemoveAll(dir2)
	query := `
		{
			me(_uid_:0x01) {
				name
				gender
				friend @filter(geq("dob", "1999-03-20")) {
					name
				}
			}
		}
	`

	js := processToJSON(t, query)
	require.JSONEq(t,
		`{"me":[{"gender":"female","name":"Michonne"}]}`, js)
}
コード例 #12
0
ファイル: query_test.go プロジェクト: dgraph-io/dgraph
func TestToJSONFilterOrFirstOffsetCount(t *testing.T) {
	dir, dir2, _ := populateGraph(t)
	defer os.RemoveAll(dir)
	defer os.RemoveAll(dir2)
	query := `
		{
			me(_uid_:0x01) {
				name
				gender
				friend(offset:1, first:1) @filter(anyof("name", "Andrea") || anyof("name", "SomethingElse Rhee") || anyof("name", "Daryl Dixon")) {
					_count_
				}
			}
		}
	`

	js := processToJSON(t, query)
	require.JSONEq(t,
		`{"me":[{"friend":[{"_count_":1}],"gender":"female","name":"Michonne"}]}`,
		js)
}
コード例 #13
0
ファイル: query_test.go プロジェクト: dgraph-io/dgraph
func TestToJSONFilterLeqFirstOffset(t *testing.T) {
	dir, dir2, _ := populateGraph(t)
	defer os.RemoveAll(dir)
	defer os.RemoveAll(dir2)
	query := `
		{
			me(_uid_:0x01) {
				name
				gender
				friend(offset:1, first:1) @filter(leq("dob", "1909-03-20")) {
					name
				}
			}
		}
	`

	js := processToJSON(t, query)
	require.JSONEq(t,
		`{"me":[{"friend":[{"name":"Andrea"}],"gender":"female","name":"Michonne"}]}`,
		js)
}
コード例 #14
0
ファイル: query_test.go プロジェクト: dgraph-io/dgraph
func TestToJSONFilterOrCount(t *testing.T) {
	dir, dir2, _ := populateGraph(t)
	defer os.RemoveAll(dir)
	defer os.RemoveAll(dir2)
	query := `
		{
			me(_uid_:0x01) {
				name
				gender
				friend @filter(anyof("name", "Andrea") || anyof("name", "Andrea Rhee")) {
					_count_
				}
			}
		}
	`

	js := processToJSON(t, query)
	require.JSONEq(t,
		`{"me":[{"friend":[{"_count_":2}],"gender":"female","name":"Michonne"}]}`,
		js)
}
コード例 #15
0
ファイル: query_test.go プロジェクト: dgraph-io/dgraph
func TestGetUIDCount(t *testing.T) {
	dir, dir2, _ := populateGraph(t)
	defer os.RemoveAll(dir)
	defer os.RemoveAll(dir2)
	query := `
		{
			me(_uid_:0x01) {
				name
				_uid_
				gender
				alive
				friend {
					_count_
				}
			}
		}
	`
	js := processToJSON(t, query)
	require.JSONEq(t,
		`{"me":[{"_uid_":"0x1","alive":true,"friend":[{"_count_":5}],"gender":"female","name":"Michonne"}]}`,
		js)
}
コード例 #16
0
ファイル: query_test.go プロジェクト: dgraph-io/dgraph
func TestGetUIDNotInChild(t *testing.T) {
	dir, dir2, _ := populateGraph(t)
	defer os.RemoveAll(dir)
	defer os.RemoveAll(dir2)
	query := `
		{
			me(_uid_:0x01) {
				name
				_uid_
				gender
				alive
				friend {
					name
				}
			}
		}
	`
	js := processToJSON(t, query)
	require.JSONEq(t,
		`{"me":[{"_uid_":"0x1","alive":true,"friend":[{"name":"Rick Grimes"},{"name":"Glenn Rhee"},{"name":"Daryl Dixon"},{"name":"Andrea"}],"gender":"female","name":"Michonne"}]}`,
		js)
}
コード例 #17
0
ファイル: query_test.go プロジェクト: dgraph-io/dgraph
func TestSchema1(t *testing.T) {
	require.NoError(t, schema.Parse("test_schema"))

	dir, dir2, _ := populateGraph(t)
	defer os.RemoveAll(dir)
	defer os.RemoveAll(dir2)

	// Alright. Now we have everything set up. Let's create the query.
	query := `
		{
			person(_uid_:0x01) {
				alive
				survival_rate
				friend
			}
		}
	`
	js := processToJSON(t, query)
	require.JSONEq(t,
		`{"person":[{"address":"31, 32 street, Jupiter","age":38,"alive":true,"friend":[{"address":"21, mark street, Mars","age":15,"name":"Rick Grimes"}],"name":"Michonne","survival_rate":98.99}]}`,
		js)
}
コード例 #18
0
ファイル: query_test.go プロジェクト: dgraph-io/dgraph
func TestFieldAlias(t *testing.T) {
	dir, dir2, _ := populateGraph(t)
	defer os.RemoveAll(dir)
	defer os.RemoveAll(dir2)

	// Alright. Now we have everything set up. Let's create the query.
	query := `
		{
			me(_uid_:0x01) {
				MyName:name
				gender
				alive
				Buddies:friend {
					BudName:name
				}
			}
		}
	`

	js := processToJSON(t, query)
	require.JSONEq(t,
		`{"me":[{"alive":true,"Buddies":[{"BudName":"Rick Grimes"},{"BudName":"Glenn Rhee"},{"BudName":"Daryl Dixon"},{"BudName":"Andrea"}],"gender":"female","MyName":"Michonne"}]}`,
		string(js))
}
コード例 #19
0
ファイル: index_test.go プロジェクト: dgraph-io/benchmarks
func testHelper(t *testing.T, prefix string) {
	var r map[string]interface{}

	input, err := ioutil.ReadFile(prefix + ".in")
	require.NoError(t, err)
	expectedOutput, err := ioutil.ReadFile(prefix + ".out")
	require.NoError(t, err)

	// Checking expected output.
	require.NoError(t, json.Unmarshal(expectedOutput, &r))
	_, found := r["me"]
	require.True(t, found)
	expectedJS, err := json.Marshal(r["me"])
	require.NoError(t, err)

	// Post the query.
	var client http.Client
	req, err := http.NewRequest("POST", *dgraph, bytes.NewReader(input))

	require.NoError(t, err)
	res, err := client.Do(req)
	require.NoError(t, err)

	body, err := ioutil.ReadAll(res.Body)
	require.NoError(t, err)

	// Check the response.
	require.NoError(t, json.Unmarshal(body, &r))
	_, found = r["me"]
	require.True(t, found)

	js, err := json.Marshal(r["me"])
	require.NoError(t, err)

	require.JSONEq(t, string(expectedJS), string(js))
}