Created
July 15, 2024 20:56
-
-
Save BK1031/444c96a81a4a781253e7d6bda9398d4f to your computer and use it in GitHub Desktop.
singlestore-go-bookstore TestCreateBook
This file contains hidden or 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
package service | |
import ( | |
"bookstore/model" | |
"testing" | |
) | |
func TestCreateBook(t *testing.T) { | |
// Arrange | |
book := model.Book{ | |
Title: "The Great Gatsby", | |
Author: "F. Scott Fitzgerald", | |
Price: 29.99, | |
Genre: "Fiction", | |
} | |
// Act | |
createdBook, err := CreateBook(book) | |
if err != nil { | |
t.Errorf("failed to create book: %s", err) | |
} | |
// Assert | |
if createdBook.ID == 0 { | |
t.Errorf("expected non-zero ID, got %d", createdBook.ID) | |
} else if createdBook.Title != book.Title { | |
t.Errorf("expected %s, got %s", book.Title, createdBook.Title) | |
} else if createdBook.Author != book.Author { | |
t.Errorf("expected %s, got %s", book.Author, createdBook.Author) | |
} else if createdBook.Price != book.Price { | |
t.Errorf("expected %f, got %f", book.Price, createdBook.Price) | |
} else if createdBook.Genre != book.Genre { | |
t.Errorf("expected %s, got %s", book.Genre, createdBook.Genre) | |
} else if createdBook.CreatedAt.IsZero() { | |
t.Errorf("expected non-zero CreatedAt, got %s", createdBook.CreatedAt) | |
} else if createdBook.UpdatedAt.IsZero() { | |
t.Errorf("expected non-zero UpdatedAt, got %s", createdBook.UpdatedAt) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment