Skip to content

Commit

Permalink
ci/cd
Browse files Browse the repository at this point in the history
  • Loading branch information
adesokanayo committed Apr 13, 2022
1 parent 2e621d7 commit 4f47e7b
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 34 deletions.
65 changes: 65 additions & 0 deletions .github/workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Test
on: [push, pull_request]
env:
ENVIRONMENT: ${{ secrets.ENVIRONMENT }}
HTTP_PORT: 8004
GRPC_PORT: 9004
GRPC_HEALTH_PORT: 10004
STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }}
JWT_PUBLIC_KEY: LS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tCk1JSUJJakFOQmdrcWhraUc5dzBCQVFFRkFBT0NBUThBTUlJQkNnS0NBUUVBdi9WR01uV2ZzM1gzNC8ycXRXenIKOXVuNjkxSXFZS2s3RWhPVE9ZT1RzRU9yNzZBZzBwZ2FXTVJ2VUFya0hudHhaL2I0VVB6dE9UT3R2akhITFlFSwpoRTA4RVcxaVVKSWpBR3JtZlkyYWlIcUF0N29JU1Jkc0plQVpCWjE0dU1aK2JsbkQ4OFRFQ294TVNCem83dHIyCnBOR1RpREs4WlQ2dFI0Tmk4WVh1TXVhY0N5V01ZNE03S3h0a0ZQVHYvalljZ05EcnhJeVphQzRYaVBlcW92NGIKVGoxRklad0xhaUF6Zklsenltbm5SUDlqN2ZUZ25kOHVYYUlqeXNKMDJubVJCY2IrOFU0OUlaVnF6ZjFjWTZDZwpBUENpT2piWU9nWEJhTjZwTFRuY2d4MEJISS9lU2xUK0w0L05vVlpyeGlnd2ZkV3RxL24wQkFXaDhzZDFHTVZFCk5RSURBUUFCCi0tLS0tRU5EIFJTQSBQVUJMSUMgS0VZLS0tLS0K

jobs:
lint:
strategy:
matrix:
go-version: [1.17.x]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}

steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v2

- name: Install golangci-lint
run: |
go get github.com/golangci/golangci-lint/cmd/[email protected]
- name: Run linters
run: |
export PATH=$PATH:$(go env GOPATH)/bin
golangci-lint run --config=.golangci_lint.yaml
test:
needs: lint
strategy:
matrix:
go-version: [1.17.x]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}

steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v2

- name: Test
run: |
go build
go test -v ./... -coverprofile=coverage.txt -cover
- name: Create Env File and Load Secret
run: |
touch .dailywellness.env
echo ${{ secrets.DAILYWELLNESS_ENV }} >> .dailywellness.env
- name: List Directory
run: |
ls
cat .dailywellness.env
30 changes: 15 additions & 15 deletions repository/firestore-repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ func (*repo) Save(post *entity.Tip) (*entity.Tip, error) {

defer client.Close()
_, _, err = client.Collection(collectionNAME).Add(ctx, map[string]interface{}{
"ID": post.ID,
"Title": post.Title,
"Text": post.Text,
"Number":post.Number,
"ID": post.ID,
"Title": post.Title,
"Text": post.Text,
"Number": post.Number,
})

if err != nil {
Expand Down Expand Up @@ -75,9 +75,9 @@ func (*repo) FindAll() ([]entity.Tip, error) {
return nil, err
}
post := entity.Tip{
ID: doc.Data()["ID"].(int64),
Title: doc.Data()["Title"].(string),
Text: doc.Data()["Text"].(string),
ID: doc.Data()["ID"].(int64),
Title: doc.Data()["Title"].(string),
Text: doc.Data()["Text"].(string),
Number: doc.Data()["Number"].(int64),
}
posts = append(posts, post)
Expand Down Expand Up @@ -112,9 +112,9 @@ func (*repo) FindOne(num int64) (*entity.Tip, error) {
return nil, err
}
post = entity.Tip{
ID: doc.Data()["ID"].(int64),
Title: doc.Data()["Title"].(string),
Text: doc.Data()["Text"].(string),
ID: doc.Data()["ID"].(int64),
Title: doc.Data()["Title"].(string),
Text: doc.Data()["Text"].(string),
Number: doc.Data()["Number"].(int64),
}

Expand All @@ -132,7 +132,7 @@ func (*repo) FindToday() (*entity.Tip, error) {
return nil, err
}

t:= time.Now().YearDay()
t := time.Now().YearDay()
today := int64(t)
defer client.Close()

Expand All @@ -150,13 +150,13 @@ func (*repo) FindToday() (*entity.Tip, error) {
return nil, err
}
post = entity.Tip{
ID: doc.Data()["ID"].(int64),
Title: doc.Data()["Title"].(string),
Text: doc.Data()["Text"].(string),
ID: doc.Data()["ID"].(int64),
Title: doc.Data()["Title"].(string),
Text: doc.Data()["Text"].(string),
Number: doc.Data()["Number"].(int64),
}

}

return &post, nil
}
}
4 changes: 2 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ func startApp() {
}
httpRouter.GET("/health", func(resp http.ResponseWriter, req *http.Request) {
resp.Write([]byte("Health check "))
resp.WriteHeader((http.StatusOK))
resp.WriteHeader(http.StatusOK)
resp.Write([]byte("Health check "))
fmt.Println("Landing Page loaded ")

})

httpRouter.GET("/readiness", func(resp http.ResponseWriter, req *http.Request) {
resp.Write([]byte("readiness check "))
resp.WriteHeader((http.StatusOK))
resp.WriteHeader(http.StatusOK)
resp.Write([]byte("Readiness check "))
fmt.Println("Landing Page loaded ")

Expand Down
16 changes: 9 additions & 7 deletions services/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ func NewTipService() postingInterface {
return &service{}
}

type postingInterface interface {
Validate(post *entity.Tip) error
Create(post *entity.Tip) (*entity.Tip, error)
FindAll() ([]entity.Tip, error)
FindOne() (*entity.Tip, error)
FindToday() (*entity.Tip, error)
}
type (
postingInterface interface {
Validate(post *entity.Tip) error
Create(post *entity.Tip) (*entity.Tip, error)
FindAll() ([]entity.Tip, error)
FindOne() (*entity.Tip, error)
FindToday() (*entity.Tip, error)
}
)

func (s *service) Validate(post *entity.Tip) error {

Expand Down
19 changes: 9 additions & 10 deletions services/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ var (

getPost func(entity.Tip) (*entity.Tip, error)
validatePost func(entity.Tip) error
findAllPost func() ([]entity.Tip, error)
createPost func(*entity.Tip)(*entity.Tip, error)
findAllPost func() ([]entity.Tip, error)
createPost func(*entity.Tip) (*entity.Tip, error)
)

type mockPosting struct{}
Expand Down Expand Up @@ -44,7 +44,7 @@ func TestValidateEmptyTitle(t *testing.T) {
//arrange
emptyTitlepost := entity.Tip{ID: 1}

validatePost = func(entity.Tip) error{
validatePost = func(entity.Tip) error {
return errors.New("empty title")
}
//act
Expand All @@ -58,7 +58,7 @@ func TestValidateEmptyTitle(t *testing.T) {

func TestValidateEmptyPost(t *testing.T) {
//arrange
validatePost = func(entity.Tip) error{
validatePost = func(entity.Tip) error {
return errors.New("empty post")
}
//act
Expand All @@ -71,7 +71,7 @@ func TestValidateEmptyPost(t *testing.T) {
func TestValidate_GoodPost(t *testing.T) {
//arrange
post := entity.Tip{ID: 1, Title: "Title", Text: "Good Post"}
validatePost = func(entity.Tip) error{
validatePost = func(entity.Tip) error {
return nil
}
//act
Expand All @@ -85,10 +85,10 @@ func TestCreatePost(t *testing.T) {
//arrange
post := entity.Tip{ID: 1, Title: "Title", Text: "Good Post"}

createPost = func (post *entity.Tip) (*entity.Tip, error){
createPost = func(post *entity.Tip) (*entity.Tip, error) {
return post, nil

}
}
//act
newPost, err := mockPostingService.Create(&post)

Expand All @@ -98,14 +98,13 @@ func TestCreatePost(t *testing.T) {
}

func TestFindAll(t *testing.T) {
var posts []entity.Tip
var posts []entity.Tip

post1 := entity.Tip{ID: 1, Title: "Title", Text: "Good Post"}
post2 := entity.Tip{ID: 2, Title: "Title2", Text: "Good Post2"}
posts = append(posts, post1, post2)


findAllPost = func() ([]entity.Tip, error){
findAllPost = func() ([]entity.Tip, error) {
return posts, nil
}
newPosts, err := mockPostingService.FindAll()
Expand Down

0 comments on commit 4f47e7b

Please sign in to comment.