-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added methods to save and fetch documents.
- Loading branch information
1 parent
1420468
commit 4ff242a
Showing
8 changed files
with
456 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,151 @@ | ||
package arango | ||
|
||
import ( | ||
|
||
"testing" | ||
) | ||
|
||
var ( | ||
db *Database | ||
) | ||
|
||
func setup() { | ||
var err error | ||
db, err = Conn( "http://root@localhost:8529" ) | ||
if err != nil { | ||
panic( err ) | ||
} | ||
|
||
db.DropDatabase( "testing" ) | ||
err = db.CreateDatabase( "testing", nil, users ) | ||
|
||
if err != nil { | ||
panic( err ) | ||
} | ||
db, err = db.UseDatabase( "testing" ) | ||
if err != nil { | ||
panic( err ) | ||
} | ||
} | ||
|
||
func teardown(){ | ||
var err error | ||
db, err = db.UseDatabase( "_system" ) | ||
if err != nil { | ||
panic( err ) | ||
} | ||
err = db.DropDatabase( "testing" ) | ||
if err != nil { | ||
panic( err ) | ||
} | ||
} | ||
|
||
type DummyDocument struct{ | ||
Hi string | ||
} | ||
|
||
type DummyFullDocument struct { | ||
DocumentImplementation | ||
Hi string | ||
} | ||
|
||
func TestSavingAndRetrievingDocument( t *testing.T ){ | ||
|
||
setup() | ||
defer teardown() | ||
|
||
c, err := db.CreateDocumentCollection( "testing" ) | ||
|
||
err = c.Save( &DummyDocument{ Hi : "Hello World" } ) | ||
|
||
if err != nil { | ||
t.Fatal( err ) | ||
} | ||
|
||
fulld := &DummyFullDocument{ | ||
Hi : "Hello World", | ||
} | ||
|
||
err = c.Save( fulld ) | ||
|
||
if err != nil { | ||
t.Fatal( err ) | ||
} | ||
|
||
if fulld.Id() == "" { | ||
t.Fatal( "Expected id to be populated in document after a save." ) | ||
} | ||
|
||
//Find it via full id | ||
ret := &DummyFullDocument{} | ||
err = c.Document( fulld.Id(), ret ) | ||
|
||
if err != nil { | ||
t.Fatal( err ) | ||
} | ||
|
||
if ret.Hi != "Hello World" { | ||
t.Fatal( "Expected to have the value for the document correctly fetched.") | ||
} | ||
|
||
if ret.Id() != fulld.Id() { | ||
t.Fatal( "Expected to have the ids for documents be equal since they are the same document.") | ||
} | ||
|
||
if ret.Key() != fulld.Key() { | ||
t.Fatal( "Expected to have the keys for documents be equal since they are the same document.") | ||
} | ||
|
||
if ret.Rev() != fulld.Rev() { | ||
t.Fatal( "Expected to have the revs for documents be equal since they are the same document.") | ||
} | ||
|
||
//Find it using a Document struct | ||
ret = &DummyFullDocument{} | ||
err = c.Document( fulld, ret ) | ||
|
||
if err != nil { | ||
t.Fatal( err ) | ||
} | ||
|
||
if ret.Hi != "Hello World" { | ||
t.Fatal( "Expected to have the value for the document correctly fetched.") | ||
} | ||
|
||
if ret.Id() != fulld.Id() { | ||
t.Fatal( "Expected to have the ids for documents be equal since they are the same document.") | ||
} | ||
|
||
if ret.Key() != fulld.Key() { | ||
t.Fatal( "Expected to have the keys for documents be equal since they are the same document.") | ||
} | ||
|
||
if ret.Rev() != fulld.Rev() { | ||
t.Fatal( "Expected to have the revs for documents be equal since they are the same document.") | ||
} | ||
|
||
//Find it by key | ||
ret = &DummyFullDocument{} | ||
err = c.Document( fulld.Key(), ret ) | ||
|
||
if err != nil { | ||
t.Fatal( err ) | ||
} | ||
|
||
if ret.Hi != "Hello World" { | ||
t.Fatal( "Expected to have the value for the document correctly fetched.") | ||
} | ||
|
||
if ret.Id() != fulld.Id() { | ||
t.Fatal( "Expected to have the ids for documents be equal since they are the same document.") | ||
} | ||
|
||
if ret.Key() != fulld.Key() { | ||
t.Fatal( "Expected to have the keys for documents be equal since they are the same document.") | ||
} | ||
|
||
if ret.Rev() != fulld.Rev() { | ||
t.Fatal( "Expected to have the revs for documents be equal since they are the same document.") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.