Skip to content

Commit

Permalink
chore(readme.md): update how to run projects and test (#29)
Browse files Browse the repository at this point in the history
* chore(readme.md): update how to run projects

* chore(test): resolve test error

* chore(readme): add title for run project

* chore(readme): fix typo
  • Loading branch information
bxcodec committed Aug 15, 2019
1 parent 60a2d43 commit 3b00474
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 78 deletions.
59 changes: 14 additions & 45 deletions README.md
Expand Up @@ -32,80 +32,49 @@ The explanation about this project's structure can read from this medium's post
### How To Run This Project
> Make Sure you have run the article.sql in your mysql
```bash
#move to directory
cd $GOPATH/src/github.com/bxcodec

# Clone into YOUR $GOPATH/src
git clone https://github.com/bxcodec/go-clean-arch.git

#move to project
cd go-clean-arch

# Install Dependencies
dep ensure
Since the project already use Go Module, I recommend to put the source code in any folder but GOPATH.

# Test the code
make test

# Run Project
go run main.go

```
Or With `go get`
> Make Sure you have run the article.sql in your mysql
#### Run the Testing

```bash
# GET WITH GO GET
go get github.com/bxcodec/go-clean-arch

# Go to directory

cd $GOPATH/src/github.com/bxcodec/go-clean-arch

# Install Dependencies
dep ensure

# Test the code
make test

# Run Project
go run main.go
$ make test
```

Or with `docker-compose`
#### Run the Applications
Here is the steps to run it with `docker-compose`

```bash
#move to directory
cd $GOPATH/src/github.com/bxcodec
$ cd workspace

# Clone into YOUR $GOPATH/src
git clone https://github.com/bxcodec/go-clean-arch.git
$ git clone https://github.com/bxcodec/go-clean-arch.git

#move to project
cd go-clean-arch
$ cd go-clean-arch

# Build the docker image first
make docker
$ make docker

# Run the application
make run
$ make run

# check if the containers are running
docker ps
$ docker ps

# Execute the call
curl localhost:9090/articles
$ curl localhost:9090/articles

# Stop
make stop
$ make stop
```


### Tools Used:
In this project, I use some tools listed below. But you can use any simmilar library that have the same purposes. But, well, different library will have different implementation type. Just be creative and use anything that you really need.

- All libraries listed in [`Gopkg.toml`](https://github.com/bxcodec/go-clean-arch/blob/master/Gopkg.toml)
- All libraries listed in [`go.mod`](https://github.com/bxcodec/go-clean-arch/blob/master/go.mod)
- ["github.com/vektra/mockery".](https://github.com/vektra/mockery) To Generate Mocks for testing needs.


Expand Down
28 changes: 1 addition & 27 deletions article/repository/mysqlarticle_test.go
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1"

articleRepo "github.com/bxcodec/go-clean-arch/article/repository"
Expand All @@ -19,11 +18,6 @@ func TestFetch(t *testing.T) {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}

defer func() {
err = db.Close()
require.NoError(t, err)
}()

mockArticles := []models.Article{
models.Article{
ID: 1, Title: "title 1", Content: "content 1",
Expand Down Expand Up @@ -59,11 +53,6 @@ func TestGetByID(t *testing.T) {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}

defer func() {
err = db.Close()
require.NoError(t, err)
}()

rows := sqlmock.NewRows([]string{"id", "title", "content", "author_id", "updated_at", "created_at"}).
AddRow(1, "title 1", "Content 1", 1, time.Now(), time.Now())

Expand Down Expand Up @@ -94,10 +83,6 @@ func TestStore(t *testing.T) {
if err != nil {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}
defer func() {
err = db.Close()
require.NoError(t, err)
}()

query := "INSERT article SET title=\\? , content=\\? , author_id=\\?, updated_at=\\? , created_at=\\?"
prep := mock.ExpectPrepare(query)
Expand All @@ -115,10 +100,7 @@ func TestGetByTitle(t *testing.T) {
if err != nil {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}
defer func() {
err = db.Close()
require.NoError(t, err)
}()

rows := sqlmock.NewRows([]string{"id", "title", "content", "author_id", "updated_at", "created_at"}).
AddRow(1, "title 1", "Content 1", 1, time.Now(), time.Now())

Expand All @@ -138,10 +120,6 @@ func TestDelete(t *testing.T) {
if err != nil {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}
defer func() {
err = db.Close()
require.NoError(t, err)
}()

query := "DELETE FROM article WHERE id = \\?"

Expand Down Expand Up @@ -173,10 +151,6 @@ func TestUpdate(t *testing.T) {
if err != nil {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}
defer func() {
err = db.Close()
require.NoError(t, err)
}()

query := "UPDATE article set title=\\?, content=\\?, author_id=\\?, updated_at=\\? WHERE ID = \\?"

Expand Down
6 changes: 0 additions & 6 deletions author/repository/mysql_test.go
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1"

"github.com/bxcodec/go-clean-arch/author/repository"
Expand All @@ -18,11 +17,6 @@ func TestGetByID(t *testing.T) {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}

defer func() {
err := db.Close()
require.NoError(t, err)
}()

rows := sqlmock.NewRows([]string{"id", "name", "updated_at", "created_at"}).
AddRow(1, "Iman Tumorang", time.Now(), time.Now())

Expand Down

0 comments on commit 3b00474

Please sign in to comment.