diff --git a/.github/workflow.yaml b/.github/workflow.yaml new file mode 100644 index 0000000..f85a783 --- /dev/null +++ b/.github/workflow.yaml @@ -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/golangci-lint@v1.41.0 + - 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 \ No newline at end of file diff --git a/repository/firestore-repo.go b/repository/firestore-repo.go index 8e7678e..65b5735 100644 --- a/repository/firestore-repo.go +++ b/repository/firestore-repo.go @@ -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 { @@ -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) @@ -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), } @@ -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() @@ -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 -} \ No newline at end of file +} diff --git a/server.go b/server.go index 5bf36fc..170a3c3 100644 --- a/server.go +++ b/server.go @@ -28,7 +28,7 @@ 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 ") @@ -36,7 +36,7 @@ func startApp() { 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 ") diff --git a/services/service.go b/services/service.go index 4bfe301..071bb5a 100644 --- a/services/service.go +++ b/services/service.go @@ -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 { diff --git a/services/service_test.go b/services/service_test.go index 19e9e43..1592475 100644 --- a/services/service_test.go +++ b/services/service_test.go @@ -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{} @@ -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 @@ -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 @@ -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 @@ -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) @@ -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()