Improved unit tests
the build failed Details

This commit is contained in:
konrad 2018-01-26 12:37:11 +01:00 committed by kolaente
parent 7ddbec7a6f
commit aa5b510424
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 38 additions and 0 deletions

View File

@ -77,4 +77,42 @@ func TestAddOrUpdateAuthor(t *testing.T) {
err = DeleteAuthorByID(0)
assert.Error(t, err)
assert.True(t, IsErrIDCannotBeZero(err))
// =======================
// Testing without a table
// Drop the table to see it fail
x.DropTables(Author{})
// Test inserting
_, err = AddOrUpdateAuthor(Author{Forename:"ff", Lastname: "fff"})
assert.Error(t, err)
// Test updating
_, err = AddOrUpdateAuthor(Author{ID: 3, Forename:"ff", Lastname: "fff"})
assert.Error(t, err)
// Delete from some nonexistent
err = DeleteAuthorByID(3)
assert.Error(t, err)
// And get from nonexistant
_, err = ListAuthors("")
assert.Error(t, err)
//Aaaaaaaaaand recreate it
x.Sync(Author{})
}
func TestGetAuthorsByBook(t *testing.T) {
// Create test database
assert.NoError(t, PrepareTestDatabase())
// Drop the table to see it fail
x.DropTables(AuthorBook{})
_, err := GetAuthorsByBook(Book{ID:1})
assert.Error(t, err)
//Aaaaaaaaaand recreate it
x.Sync(AuthorBook{})
}