diff --git a/models/author_test.go b/models/author_test.go index 752d30d..dc0a716 100644 --- a/models/author_test.go +++ b/models/author_test.go @@ -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{}) +} \ No newline at end of file