Skip to content

Commit

Permalink
fix: CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
JOJOSoderqvist committed Dec 18, 2024
1 parent d364a93 commit c0a8f18
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 158 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pull_requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
build:
name: go-build
name: go-build and test
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.23
Expand All @@ -20,8 +20,8 @@ jobs:
- name: Get dependencies
run: go mod tidy

# - name: Run make test
# run: make test
- name: Run make test
run: go test ./...

golangci:
name: go-lint
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
build:
name: go-build
name: go-build and test
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.23
Expand All @@ -20,8 +20,8 @@ jobs:
- name: Get dependencies
run: go mod tidy

# - name: Run make test
# run: make test
- name: Run make test
run: go test ./...

linter:
name: go-lint
Expand All @@ -38,14 +38,15 @@ jobs:

deploy:
name: Deploy to VM
needs: [build]
needs: [build, linter]
runs-on: ubuntu-latest
environment: CICD
timeout-minutes: 40
timeout-minutes: 50
steps:
- name: Execute commands over ssh
uses: appleboy/ssh-action@master
with:
command_timeout: '50m'
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSH_KEY }}
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ go.work.sum

.idea

qodana.yaml
qodana.yaml

*.log
20 changes: 20 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
issues:
exclude-rules:
- linters:
- staticcheck
text: "SA1029:"
- linters:
- staticcheck
text: "SA6005:"
- linters:
- staticcheck
text: "SA4010:"
- linters:
- staticcheck
text: "SA1006:"
- linters:
- govet
text: "printf:"
- linters:
- gosimple
text: "S1009:"
14 changes: 0 additions & 14 deletions internal/grpc_api/profile/dto.go
Original file line number Diff line number Diff line change
@@ -1,15 +1 @@
package profile

import (
profile_grpc "github.com/go-park-mail-ru/2024_2_kotyari/api/protos/profile/gen"
"github.com/go-park-mail-ru/2024_2_kotyari/internal/model"
)

func toGrpcModel(p model.Profile) *profile_grpc.GetProfileResponse {
return &profile_grpc.GetProfileResponse{
Email: p.Email,
Username: p.Username,
Gender: p.Gender,
AvatarUrl: p.AvatarURL,
}
}
76 changes: 0 additions & 76 deletions internal/repository/category/delivery.log

This file was deleted.

16 changes: 2 additions & 14 deletions internal/repository/category/get_related_products_by_productid.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,14 @@ func (cs *CategoriesStore) GetRelatedProductsByProductID(ctx context.Context, pr
cs.log.Info("[CategoriesStore.GetRelatedProductsByProductID] Started executing",
slog.Any("request-id", requestID))

categories, err := cs.categoriesGetter.GetProductCategories(ctx, productID)
if err != nil {
}
//cs.log.Info("[CategoriesStore.GetRelatedProductsByProductID] Вывод полученных категорий", slog.Any("categories", categories))
if len(categories) == 0 {
}
categories, _ := cs.categoriesGetter.GetProductCategories(ctx, productID)

var allProducts []model.ProductCatalog
seenProducts := make(map[uint32]bool)

for _, category := range categories {

products, err := cs.GetProductsByCategoryLink(ctx, category.LinkTo, sortField, sortOrder)
if err != nil {

}
products, _ := cs.GetProductsByCategoryLink(ctx, category.LinkTo, sortField, sortOrder)

for _, product := range products {
if !seenProducts[product.ID] {
Expand All @@ -45,9 +37,5 @@ func (cs *CategoriesStore) GetRelatedProductsByProductID(ctx context.Context, pr
}
}

if len(allProducts) == 0 {

}

return allProducts, nil
}
9 changes: 4 additions & 5 deletions internal/repository/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package file
import (
"fmt"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -26,7 +25,7 @@ func TestGetFile(t *testing.T) {
filename: "test-file.txt",
setup: func() string {
filePath := filepath.Join(baseDir, "test-file.txt")
err := ioutil.WriteFile(filePath, []byte("content"), 0644)
err := os.WriteFile(filePath, []byte("content"), 0644)
if err != nil {
t.Fatalf("Ошибка при создании файла для теста: %v", err)
}
Expand Down Expand Up @@ -82,7 +81,7 @@ func TestSaveFile(t *testing.T) {
name: "Success",
filename: "new-file.txt",
setup: func() (*os.File, string) {
tempFile, _ := ioutil.TempFile("", "temp-file")
tempFile, _ := os.CreateTemp("", "temp-file")
_, _ = tempFile.WriteString("test content")
return tempFile, filepath.Join(baseDir, "new-file.txt")
},
Expand All @@ -93,7 +92,7 @@ func TestSaveFile(t *testing.T) {
filename: "existing-file.txt",
setup: func() (*os.File, string) {
filePath := filepath.Join(baseDir, "existing-file.txt")
err := ioutil.WriteFile(filePath, []byte("existing content"), 0644)
err := os.WriteFile(filePath, []byte("existing content"), 0644)
assert.NoError(t, err)
return nil, filePath
},
Expand All @@ -103,7 +102,7 @@ func TestSaveFile(t *testing.T) {
name: "Error Creating File",
filename: "invalid-path/invalid-file.txt",
setup: func() (*os.File, string) {
tempFile, _ := ioutil.TempFile("", "temp-file")
tempFile, _ := os.CreateTemp("", "temp-file")
_, _ = tempFile.WriteString("test content")
return tempFile, ""
},
Expand Down
3 changes: 1 addition & 2 deletions internal/repository/orders/get_nearest_delivery_date_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ func (suite *OrdersRepoGetNearestDeliveryDateSuite) TestGetNearestDeliveryDate_N
}

func (suite *OrdersRepoGetNearestDeliveryDateSuite) TestGetNearestDeliveryDate_QueryError() {
ctx := context.Background()
requestID := uuid.New()
ctx = context.WithValue(context.Background(), utils.RequestIDName, requestID)
ctx := context.WithValue(context.Background(), utils.RequestIDName, requestID)
var userID uint32 = 12345

expectedError := errors.New("database error")
Expand Down
6 changes: 2 additions & 4 deletions internal/repository/orders/get_order_by_id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ func (suite *OrdersRepoGetOrderByIdSuite) SetupTest() {
}

func (suite *OrdersRepoGetOrderByIdSuite) TestGetOrderById_Success() {
ctx := context.Background()
requestID := uuid.New()
ctx = context.WithValue(context.Background(), utils.RequestIDName, requestID)
ctx := context.WithValue(context.Background(), utils.RequestIDName, requestID)
userID := uint32(12345)
orderID := uuid.New()

Expand Down Expand Up @@ -70,9 +69,8 @@ func (suite *OrdersRepoGetOrderByIdSuite) TestGetOrderById_Success() {
}

func (suite *OrdersRepoGetOrderByIdSuite) TestGetOrderById_QueryError() {
ctx := context.Background()
requestID := uuid.New()
ctx = context.WithValue(context.Background(), utils.RequestIDName, requestID)
ctx := context.WithValue(context.Background(), utils.RequestIDName, requestID)
userID := uint32(12345)
orderID := uuid.New()

Expand Down
6 changes: 2 additions & 4 deletions internal/repository/orders/get_orders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ func (suite *OrdersRepoGetOrdersSuite) SetupTest() {
}

func (suite *OrdersRepoGetOrdersSuite) TestGetOrders_Success() {
ctx := context.Background()
requestID := uuid.New()
ctx = context.WithValue(context.Background(), utils.RequestIDName, requestID)
ctx := context.WithValue(context.Background(), utils.RequestIDName, requestID)
userID := uint32(12345)

orderID := uuid.New()
Expand Down Expand Up @@ -71,9 +70,8 @@ func (suite *OrdersRepoGetOrdersSuite) TestGetOrders_Success() {
}

func (suite *OrdersRepoGetOrdersSuite) TestGetOrders_QueryError() {
ctx := context.Background()
requestID := uuid.New()
ctx = context.WithValue(context.Background(), utils.RequestIDName, requestID)
ctx := context.WithValue(context.Background(), utils.RequestIDName, requestID)
userID := uint32(12345)

expectedSQL := `
Expand Down
29 changes: 0 additions & 29 deletions internal/repository/product/dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,3 @@ func (dto *dtoOptionBlock) ToModel() model.OptionsBlock {
Options: options,
}
}

func optionToDTO(option model.Option) dtoOption {
return dtoOption{
Link: option.Link,
Value: option.Value,
}
}

func optionsBlockToDTO(optionsBlock model.OptionsBlock) dtoOptionBlock {
options := make([]dtoOption, len(optionsBlock.Options))
for i, option := range optionsBlock.Options {
options[i] = optionToDTO(option)
}
return dtoOptionBlock{
Title: optionsBlock.Title,
Type: optionsBlock.Type,
Options: options,
}
}

func optionsToDto(opts model.Options) []dtoOptionBlock {
res := make([]dtoOptionBlock, len(opts.Values))

for i, option := range opts.Values {
res[i] = optionsBlockToDTO(option)
}

return res
}
1 change: 0 additions & 1 deletion internal/usecase/profile/get_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

var (
testContextRequestIDValue = uuid.New()
dbTestError = errors.New("ошибка базы данных")
)

const testContextRequestIDKey = "request-id"
Expand Down

0 comments on commit c0a8f18

Please sign in to comment.