Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run the tests with neo4j 2.2.0 and NEO4J_URL env variable #72

Merged
merged 1 commit into from
Apr 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ before_install:
- sh start-neo4j.sh

env:
- NEO4J_VERSION="2.1.2"
global:
- NEO4J_VERSION="2.2.0"
- NEO4J_URL=http://localhost:7474/db/data/

script:
- go test -v
14 changes: 10 additions & 4 deletions connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package neoism
import (
"net/http"
"net/url"
"strings"

"github.com/jmcvetta/napping"
)
Expand All @@ -23,12 +24,17 @@ func Connect(uri string) (*Database, error) {
Header: &h,
},
}
parsedUrl, err := url.Parse(uri)

// trailing slash is important, check if it's not there and add it
if !strings.HasSuffix(uri, "/") {
uri += "/"
}
parsedURL, err := url.Parse(uri)
if err != nil {
return nil, err
}
if parsedUrl.User != nil {
db.Session.Userinfo = parsedUrl.User
if parsedURL.User != nil {
db.Session.Userinfo = parsedURL.User
}
return connectWithRetry(db, parsedUrl, 0)
return connectWithRetry(db, parsedURL, 0)
}
2 changes: 1 addition & 1 deletion database.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func PropertyKeys(db *Database) ([]string, error) {
propertyKeys := []string{}
ne := NeoError{}

uri := db.Url + "/" + "propertykeys"
uri := db.Url + "propertykeys"
resp, err := db.Session.Get(uri, nil, &propertyKeys, &ne)
if err != nil {
return propertyKeys, err
Expand Down
19 changes: 14 additions & 5 deletions database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ package neoism
import (
"log"
"os"
"regexp"
"testing"

"github.com/bmizerany/assert"
Expand All @@ -39,7 +40,9 @@ import (

func connectTest(t *testing.T) *Database {
log.SetFlags(log.Ltime | log.Lshortfile)
db, err := dbConnect("http://localhost:7474/db/data")
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)
Expand Down Expand Up @@ -73,8 +76,9 @@ func rndStr(t *testing.T) string {

func TestConnect(t *testing.T) {
db := connectTest(t)
url := os.Getenv("NEO4J_URL")
logPretty(db)
assert.Equal(t, "http://localhost:7474/db/data", db.Url)
assert.Equal(t, url, db.Url)
}

func TestConnectInvalidUrl(t *testing.T) {
Expand All @@ -95,15 +99,20 @@ func TestConnectInvalidUrl(t *testing.T) {
//
// Not Found
//
_, err = dbConnect("http://localhost:7474/db/datadatadata")
url := os.Getenv("NEO4J_URL")
_, err = dbConnect(url + "foo/")
assert.Equal(t, InvalidDatabase, err)
}

func TestConnectIncompleteUrl(t *testing.T) {
url := os.Getenv("NEO4J_URL")
// url now has the format hostname:port/db/data, delete everything after the port
regex := regexp.MustCompile(`^(https?:\/\/[^:]+:\d+)\/.*$`)
replaced := regex.ReplaceAllString(url, "$1")
//
// 200 Success and HTML returned
//
_, err := dbConnect("http://localhost:7474")
_, err := dbConnect(replaced)
if err != nil {
t.Fatal("Hardsetting path on incomplete url failed")
}
Expand All @@ -115,7 +124,7 @@ func TestPropertyKeys(t *testing.T) {

// Prepare query for testing data creation
var queryString string
createdPropertyKeys := make([]string, 0)
var createdPropertyKeys []string
for i := 0; i < 10; i++ {
propertyKeyNodeA := rndStr(t)
propertyKeyRel := rndStr(t)
Expand Down
5 changes: 4 additions & 1 deletion start-neo4j.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/bin/sh

DIR="neo4j-community-2.1.2"
DIR="neo4j-community-2.2.0"
FILE="$DIR-unix.tar.gz"

wget "http://dist.neo4j.org/$FILE"
tar zxf $FILE
# Disable authentication, if we enable it, we have to change the default neo4j user
# password and then run all the tests with a different one
sed -i "s/auth_enabled\=true/auth_enabled\=false/g" $DIR/conf/neo4j-server.properties
$DIR/bin/neo4j start
sleep 3