Last active
July 7, 2017 10:03
-
-
Save bxcodec/d65ae5721eb46126108a962a869e0cf2 to your computer and use it in GitHub Desktop.
Repository Test
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
func TestGetByID(t *testing.T) { | |
db, mock, err := sqlmock.New() | |
if err != nil { | |
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) | |
} | |
defer db.Close() | |
rows := sqlmock.NewRows([]string{"id", "title", "content", "updated_at", "created_at"}). | |
AddRow(1, "title 1", "Content 1", time.Now(), time.Now()) | |
query := "SELECT id,title,content,updated_at, created_at FROM article WHERE ID = \\?" | |
mock.ExpectQuery(query).WillReturnRows(rows) | |
a := articleRepo.NewMysqlArticleRepository(db) | |
num := int64(1) | |
anArticle, err := a.GetByID(num) | |
assert.NoError(t, err) | |
assert.NotNil(t, anArticle) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment