예제 #1
0
// 18.4.2. Create Node with properties
func TestGetOrCreateNode(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	label, err := randutil.String(12, randutil.Alphabet)
	if err != nil {
		t.Fatal(err)
	}
	key, err := randutil.String(12, randutil.Alphabet)
	if err != nil {
		t.Fatal(err)
	}
	value, err := randutil.String(12, randutil.Alphabet)
	if err != nil {
		t.Fatal(err)
	}
	p0 := Props{key: value, "foo": "bar"}
	p1 := Props{key: value}
	p2 := Props{"foo": "bar"}
	//
	// Create unique node
	//
	n0, created, err := db.GetOrCreateNode(label, key, p0)
	if err != nil {
		t.Fatal(err)
	}
	if !created {
		t.Fatal("Failed to create unique node")
	}
	check0, err := n0.Properties()
	if err != nil {
		t.Fatal(err)
	}
	assert.Equal(t, p0, check0)
	//
	// Get unique node
	//
	n1, created, err := db.GetOrCreateNode(label, key, p1)
	if err != nil {
		t.Fatal(err)
	}
	if created {
		t.Fatal("Failed to retrieve unique node")
	}
	check1, err := n1.Properties()
	if err != nil {
		t.Fatal(err)
	}
	assert.Equal(t, p0, check1)
	//
	// No key in props
	//
	_, _, err = db.GetOrCreateNode(label, key, p2)
	assert.NotEqual(t, nil, err)
	//
	// Empty label
	//
	_, _, err = db.GetOrCreateNode("", key, p0)
	assert.NotEqual(t, nil, err)
}
예제 #2
0
func TestInvalidUrl(t *testing.T) {
	//
	//  Missing protocol scheme - url.Parse should fail
	//

	url := "://foobar.com"
	_, err := Get(url, nil, nil, nil)
	assert.NotEqual(t, nil, err)
	//
	// Unsupported protocol scheme - HttpClient.Do should fail
	//
	url = "foo://bar.com"
	_, err = Get(url, nil, nil, nil)
	assert.NotEqual(t, nil, err)
}
예제 #3
0
// 18.7.7. Delete a named property from a node
func TestDeleteNamedPropertyFromNode(t *testing.T) {
	db := connectTest(t)
	defer cleanup(t, db)
	// Create
	props0 := Props{"foo": "bar"}
	props1 := Props{"foo": "bar", "spam": "eggs"}
	n0, _ := db.CreateNode(props1)
	// Delete
	err := n0.DeleteProperty("spam")
	if err != nil {
		t.Error(err)
	}
	// Confirm
	checkProps, _ := n0.Properties()
	assert.Equalf(t, props0, checkProps, "Failed to remove named property with DeleteProperty().")
	//
	// Delete non-existent property
	//
	err = n0.DeleteProperty("eggs")
	assert.NotEqual(t, nil, err)
	//
	// Delete and check 404
	//
	n0.Delete()
	err = n0.DeleteProperty("spam")
	assert.Equal(t, NotFound, err)
}
예제 #4
0
func connectTest(t *testing.T) *Database {
	log.SetFlags(log.Ltime | log.Lshortfile)
	url := os.Getenv("NEO4J_URL")
	assert.NotEqual(t, "", url, "NEO4J_URL env variable must be provided")
	db, err := dbConnect(url)
	// db.Session.Log = true
	if err != nil {
		t.Fatal(err)
	}
	return db
}
예제 #5
0
func TestCypherBadQuery(t *testing.T) {
	db := connectTest(t)
	cq := CypherQuery{
		Statement: "foobar",
	}
	err := db.Cypher(&cq)
	ne, ok := err.(NeoError)
	if !ok {
		t.Error(err)
	}
	s := ne.Error()
	assert.NotEqual(t, "", s)
}
예제 #6
0
func TestPostUnmarshallable(t *testing.T) {
	srv := httptest.NewServer(http.HandlerFunc(HandlePost))
	defer srv.Close()
	type ft func()
	var f ft
	url := "http://" + srv.Listener.Addr().String()
	res := structType{}
	payload := f
	_, err := Post(url, &payload, &res, nil)
	assert.NotEqual(t, nil, err)
	_, ok := err.(*json.UnsupportedTypeError)
	if !ok {
		t.Log(err)
		t.Error("Expected json.UnsupportedTypeError")
	}
}
예제 #7
0
func TestBadCreateLegacyRelIndex(t *testing.T) {
	db := connectTest(t)
	_, err := db.CreateLegacyRelIndex("", "", "")
	assert.NotEqual(t, nil, err)
}