3 Commits
Author SHA1 Message Date
txix ec0f1a02d1 2025-05-27 15:03:30: merge [master:f7d84c21ab1049a1f10eacacc773ddeead8d619b];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s
2025-05-27 15:03:30 +03:00
txix 65cfb65f8e 2025-05-26 17:34:40: merge [master:d02a58345e9261c6f2b75cea3d6c36e07d9a7cfc]; 2025-05-26 17:34:40 +03:00
txix c0687a264e 2025-05-26 17:31:46: merge [master:4b0510d2764306aa9a1a7375512e74d7d7876cef]; 2025-05-26 17:31:46 +03:00
21 changed files with 496 additions and 51 deletions

No files matched your search

+60
View File
@@ -0,0 +1,60 @@
name: Create and publish a Docker image
on:
push:
tags:
- 'v*'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
APP_NAME: ${{ github.event.repository.name }}
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get version from tag
id: version_reader
run: |
VERSION=${GITHUB_REF_NAME#v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver: docker-container
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.version_reader.outputs.version }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
labels: |
org.opencontainers.image.title=${{ env.IMAGE_NAME }}
org.opencontainers.image.version=${{ steps.version_reader.outputs.version }}
build-args: |
app_name=${{ env.APP_NAME }}
version=${{ steps.version_reader.outputs.version }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v2
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
+1 -1
View File
@@ -1 +1 @@
5.3.0 5.4.0
+5
View File
@@ -1,3 +1,8 @@
### v5.4.0
* Добавлен новый endpoint: `/access_list/delete_list` для удаления методов из списка доступов у приложений
### v5.3.1
* добавлен `Dockerfile` и скрипт для сборки и публикации образа в `GitHub Contaier Registry`
* обновлены зависимости
### v5.3.0 ### v5.3.0
* Добавлен новый endpoint: `/application/get_application_by_token` * Добавлен новый endpoint: `/application/get_application_by_token`
### v5.2.1 ### v5.2.1
+47
View File
@@ -0,0 +1,47 @@
FROM golang:1.24-alpine as builder
WORKDIR /build
ARG version
ENV version_env=$version
ARG app_name
ENV app_name_env=$app_name
COPY . .
RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,source=go.sum,target=go.sum \
--mount=type=bind,source=go.mod,target=go.mod \
go mod download -x
RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,target=. \
go build -ldflags="-X 'main.version=$version_env'" -o /main .
FROM alpine:3.21
RUN apk add --no-cache tzdata
RUN cp /usr/share/zoneinfo/Europe/Moscow /etc/localtime
RUN echo "Europe/Moscow" > /etc/timezone
ARG UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
appuser
RUN mkdir -p /app/data
RUN chown appuser:appuser /app/data
VOLUME /app/data
USER appuser
WORKDIR /app
ARG app_name
ENV app_name_env=$app_name
COPY --from=builder main /app/$app_name_env
COPY /conf/config.yml /app/config.yml
COPY /conf/default_remote_config.json* /app/default_remote_config.json
COPY /migrations /app/migrations
ENTRYPOINT /app/$app_name_env
+3 -1
View File
@@ -2,8 +2,11 @@ package assembly
import ( import (
"context" "context"
"github.com/txix-open/isp-kit/rc" "github.com/txix-open/isp-kit/rc"
"isp-system-service/conf"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/txix-open/isp-kit/app" "github.com/txix-open/isp-kit/app"
"github.com/txix-open/isp-kit/bootstrap" "github.com/txix-open/isp-kit/bootstrap"
@@ -12,7 +15,6 @@ import (
"github.com/txix-open/isp-kit/dbx" "github.com/txix-open/isp-kit/dbx"
"github.com/txix-open/isp-kit/grpc" "github.com/txix-open/isp-kit/grpc"
"github.com/txix-open/isp-kit/log" "github.com/txix-open/isp-kit/log"
"isp-system-service/conf"
) )
type Assembly struct { type Assembly struct {
+28
View File
@@ -15,6 +15,7 @@ type AccessListService interface {
GetById(ctx context.Context, appId int) ([]domain.MethodInfo, error) GetById(ctx context.Context, appId int) ([]domain.MethodInfo, error)
SetOne(ctx context.Context, request domain.AccessListSetOneRequest) (*domain.AccessListSetOneResponse, error) SetOne(ctx context.Context, request domain.AccessListSetOneRequest) (*domain.AccessListSetOneResponse, error)
SetList(ctx context.Context, req domain.AccessListSetListRequest) ([]domain.MethodInfo, error) SetList(ctx context.Context, req domain.AccessListSetListRequest) ([]domain.MethodInfo, error)
DeleteList(ctx context.Context, req domain.AccessListDeleteListRequest) error
} }
type AccessList struct { type AccessList struct {
@@ -113,3 +114,30 @@ func (c AccessList) SetList(ctx context.Context, req domain.AccessListSetListReq
return result, nil return result, nil
} }
} }
// DeleteList godoc
//
// @Tags accessList
// @Summary Удалить список доступных методов для приложения
// @Description Удаляет заданный список методов для приложения
// @Accept json
// @Produce json
// @Param body body domain.AccessListDeleteListRequest false "тело запроса"
// @Success 200 {object} any
// @Failure 404 {object} apierrors.Error
// @Failure 500 {object} apierrors.Error
// @Router /access_list/delete_list [POST]
func (c AccessList) DeleteList(ctx context.Context, req domain.AccessListDeleteListRequest) error {
err := c.service.DeleteList(ctx, req)
switch {
case errors.Is(err, domain.ErrApplicationNotFound):
return apierrors.New(
codes.NotFound,
domain.ErrCodeApplicationNotFound,
fmt.Sprintf("application with id %d not found", req.AppId),
err,
)
default:
return err
}
}
+2 -1
View File
@@ -3,8 +3,9 @@ package controller
import ( import (
"context" "context"
"github.com/pkg/errors"
"isp-system-service/domain" "isp-system-service/domain"
"github.com/pkg/errors"
) )
type SecureService interface { type SecureService interface {
+41
View File
@@ -10,6 +10,19 @@ definitions:
errorMessage: errorMessage:
type: string type: string
type: object type: object
domain.AccessListDeleteListRequest:
properties:
appId:
type: integer
methods:
items:
type: string
minItems: 1
type: array
required:
- appId
- methods
type: object
domain.AccessListSetListRequest: domain.AccessListSetListRequest:
properties: properties:
appId: appId:
@@ -389,6 +402,34 @@ info:
title: isp-system-service title: isp-system-service
version: 1.0.0 version: 1.0.0
paths: paths:
/access_list/delete_list:
post:
consumes:
- application/json
description: Удаляет заданный список методов для приложения
parameters:
- description: тело запроса
in: body
name: body
schema:
$ref: '#/definitions/domain.AccessListDeleteListRequest'
produces:
- application/json
responses:
"200":
description: OK
schema: {}
"404":
description: Not Found
schema:
$ref: '#/definitions/apierrors.Error'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/apierrors.Error'
summary: Удалить список доступных методов для приложения
tags:
- accessList
/access_list/get_by_id: /access_list/get_by_id:
post: post:
consumes: consumes:
+5
View File
@@ -20,3 +20,8 @@ type MethodInfo struct {
Method string Method string
Value bool Value bool
} }
type AccessListDeleteListRequest struct {
AppId int `validate:"required"`
Methods []string `validate:"required,min=1"`
}
+1 -1
View File
@@ -7,7 +7,7 @@ require (
github.com/jackc/pgx/v5 v5.7.4 github.com/jackc/pgx/v5 v5.7.4
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.10.0 github.com/stretchr/testify v1.10.0
github.com/txix-open/isp-kit v1.48.1 github.com/txix-open/isp-kit v1.51.0
github.com/txix-open/jsonschema v1.3.0 github.com/txix-open/jsonschema v1.3.0
google.golang.org/grpc v1.72.0 google.golang.org/grpc v1.72.0
) )
+4 -4
View File
@@ -144,10 +144,10 @@ github.com/txix-open/bellows v1.2.0 h1:CXv8nQaZtB/micraeRilYyj/gtfv+bqBgP5aPYQgj
github.com/txix-open/bellows v1.2.0/go.mod h1:qbKCy+RTgD30Qpw1fyb3y3jp5Y9mGhLLxgae1l0W92o= github.com/txix-open/bellows v1.2.0/go.mod h1:qbKCy+RTgD30Qpw1fyb3y3jp5Y9mGhLLxgae1l0W92o=
github.com/txix-open/etp/v4 v4.0.1 h1:5VSYgGsvnMz0tvUHsjVWFETI0qWBTCF1O3ARCHaCIgA= github.com/txix-open/etp/v4 v4.0.1 h1:5VSYgGsvnMz0tvUHsjVWFETI0qWBTCF1O3ARCHaCIgA=
github.com/txix-open/etp/v4 v4.0.1/go.mod h1:FIu7TUDdwcgmtmF6tFTV1bGA2fRY/iVaPQdsGzvqYc8= github.com/txix-open/etp/v4 v4.0.1/go.mod h1:FIu7TUDdwcgmtmF6tFTV1bGA2fRY/iVaPQdsGzvqYc8=
github.com/txix-open/grmq v1.8.0 h1:YXTruBap7EQZ6WNOhjoFqx/XBYMBhgeYM4mzNkX+bzU= github.com/txix-open/grmq v1.8.1 h1:bcPLuYZXJ+1h9D3w7JYzUTypnQsw9XAT0Ftl/Fu+cZA=
github.com/txix-open/grmq v1.8.0/go.mod h1:EyFOP17KrwEFOUjR+PH8iH3LCtiN9TSQ8t0ysyk62po= github.com/txix-open/grmq v1.8.1/go.mod h1:EyFOP17KrwEFOUjR+PH8iH3LCtiN9TSQ8t0ysyk62po=
github.com/txix-open/isp-kit v1.48.1 h1:LZGZSpjUIaUfUQOGOHgRm9Q977su/C/rv3bI4w+x9iw= github.com/txix-open/isp-kit v1.51.0 h1:sSDs/M5EaAiIJGbefRprbZH2GgCfdjwgpUV94NWd73A=
github.com/txix-open/isp-kit v1.48.1/go.mod h1:qp0pbpsUqaAKhYGKGArYnBd0u7UBYuh561Q4MFkEqgs= github.com/txix-open/isp-kit v1.51.0/go.mod h1:OkscabRkpFGjUOFrbPM7yTKD/Br2/iv5/PWr/T2Jtd4=
github.com/txix-open/jsonschema v1.3.0 h1:XGuOTg22G7PdqfKypjajM20/i5FyGfFYsJKmheebKi4= github.com/txix-open/jsonschema v1.3.0 h1:XGuOTg22G7PdqfKypjajM20/i5FyGfFYsJKmheebKi4=
github.com/txix-open/jsonschema v1.3.0/go.mod h1:l8YDZ1nvJrw6uxWowSVOxCV/ebiMJyapffW87ZEqH00= github.com/txix-open/jsonschema v1.3.0/go.mod h1:l8YDZ1nvJrw6uxWowSVOxCV/ebiMJyapffW87ZEqH00=
github.com/txix-open/validator/v10 v10.0.0-20250506161033-f8ce404fffdb h1:UJgT4u/QMv5QHKOQeJ7igShHa36c2/vIRqJiRLdDlf0= github.com/txix-open/validator/v10 v10.0.0-20250506161033-f8ce404fffdb h1:UJgT4u/QMv5QHKOQeJ7igShHa36c2/vIRqJiRLdDlf0=
+3 -2
View File
@@ -1,11 +1,12 @@
package main package main
import ( import (
"github.com/txix-open/isp-kit/bootstrap"
"github.com/txix-open/isp-kit/shutdown"
"isp-system-service/assembly" "isp-system-service/assembly"
"isp-system-service/conf" "isp-system-service/conf"
"isp-system-service/routes" "isp-system-service/routes"
"github.com/txix-open/isp-kit/bootstrap"
"github.com/txix-open/isp-kit/shutdown"
) )
var ( var (
+3 -2
View File
@@ -4,12 +4,13 @@ import (
"context" "context"
"database/sql" "database/sql"
"isp-system-service/domain"
"isp-system-service/entity"
"github.com/Masterminds/squirrel" "github.com/Masterminds/squirrel"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/txix-open/isp-kit/db" "github.com/txix-open/isp-kit/db"
"github.com/txix-open/isp-kit/db/query" "github.com/txix-open/isp-kit/db/query"
"isp-system-service/domain"
"isp-system-service/entity"
) )
type AccessList struct { type AccessList struct {
+3 -2
View File
@@ -4,12 +4,13 @@ import (
"context" "context"
"database/sql" "database/sql"
"isp-system-service/domain"
"isp-system-service/entity"
"github.com/Masterminds/squirrel" "github.com/Masterminds/squirrel"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/txix-open/isp-kit/db" "github.com/txix-open/isp-kit/db"
"github.com/txix-open/isp-kit/db/query" "github.com/txix-open/isp-kit/db/query"
"isp-system-service/domain"
"isp-system-service/entity"
) )
type Domain struct { type Domain struct {
+3 -2
View File
@@ -4,12 +4,13 @@ import (
"context" "context"
"database/sql" "database/sql"
"isp-system-service/domain"
"isp-system-service/entity"
"github.com/Masterminds/squirrel" "github.com/Masterminds/squirrel"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/txix-open/isp-kit/db" "github.com/txix-open/isp-kit/db"
"github.com/txix-open/isp-kit/db/query" "github.com/txix-open/isp-kit/db/query"
"isp-system-service/domain"
"isp-system-service/entity"
) )
type Token struct { type Token struct {
+7 -1
View File
@@ -1,10 +1,11 @@
package routes package routes
import ( import (
"isp-system-service/controller"
"github.com/txix-open/isp-kit/cluster" "github.com/txix-open/isp-kit/cluster"
"github.com/txix-open/isp-kit/grpc" "github.com/txix-open/isp-kit/grpc"
"github.com/txix-open/isp-kit/grpc/endpoint" "github.com/txix-open/isp-kit/grpc/endpoint"
"isp-system-service/controller"
) )
type Controllers struct { type Controllers struct {
@@ -73,6 +74,11 @@ func accessListCluster(c Controllers) []cluster.EndpointDescriptor {
Inner: true, Inner: true,
Handler: c.AccessList.SetList, Handler: c.AccessList.SetList,
}, },
{
Path: "system/access_list/delete_list",
Inner: true,
Handler: c.AccessList.DeleteList,
},
} }
} }
+13
View File
@@ -11,6 +11,7 @@ import (
type AccessListRepo interface { type AccessListRepo interface {
GetAccessListByAppId(ctx context.Context, appId int) ([]entity.AccessList, error) GetAccessListByAppId(ctx context.Context, appId int) ([]entity.AccessList, error)
DeleteAccessList(ctx context.Context, appId int, methods []string) error
} }
type AccessListSetOneTx interface { type AccessListSetOneTx interface {
@@ -155,3 +156,15 @@ func (s AccessList) SetList(ctx context.Context, req domain.AccessListSetListReq
return methodInfos, nil return methodInfos, nil
} }
func (s AccessList) DeleteList(ctx context.Context, req domain.AccessListDeleteListRequest) error {
_, err := s.appRepo.GetApplicationById(ctx, req.AppId)
if err != nil {
return errors.WithMessage(err, "get application by id")
}
err = s.accessListRepo.DeleteAccessList(ctx, req.AppId, req.Methods)
if err != nil {
return errors.WithMessage(err, "delete access_list")
}
return nil
}
+2 -1
View File
@@ -3,9 +3,10 @@ package service
import ( import (
"context" "context"
"github.com/pkg/errors"
"isp-system-service/domain" "isp-system-service/domain"
"isp-system-service/entity" "isp-system-service/entity"
"github.com/pkg/errors"
) )
type Domain struct { type Domain struct {
+231
View File
@@ -0,0 +1,231 @@
package tests_test
import (
"testing"
"github.com/txix-open/isp-kit/dbx"
"isp-system-service/assembly"
"isp-system-service/conf"
"isp-system-service/domain"
"isp-system-service/entity"
"isp-system-service/repository"
"github.com/stretchr/testify/suite"
"github.com/txix-open/isp-kit/grpc/client"
"github.com/txix-open/isp-kit/test"
"github.com/txix-open/isp-kit/test/dbt"
"github.com/txix-open/isp-kit/test/fake"
"github.com/txix-open/isp-kit/test/grpct"
)
func TestAccessListSuite(t *testing.T) {
t.Parallel()
suite.Run(t, &AccessListSuite{})
}
type AccessListSuite struct {
suite.Suite
test *test.Test
testDb *dbt.TestDb
api *client.Client
accessListRepo repository.AccessList
appId int
}
func (s *AccessListSuite) SetupTest() {
s.test, _ = test.New(s.T())
s.testDb = dbt.New(s.test, dbx.WithMigrationRunner("../migrations", s.test.Logger()))
locator := assembly.NewLocator(s.testDb, s.test.Logger())
config := locator.Config(conf.Remote{})
_, s.api = grpct.TestServer(s.test, config.Handler)
s.accessListRepo = repository.NewAccessList(s.testDb)
createdDomain, err := repository.NewDomain(s.testDb).CreateDomain(
s.T().Context(),
fake.It[string](),
fake.It[string](),
1,
)
s.Require().NoError(err)
appGroup, err := repository.NewAppGroup(s.testDb).CreateAppGroup(
s.T().Context(),
fake.It[string](),
fake.It[string](),
createdDomain.Id,
)
s.Require().NoError(err)
s.appId = fake.It[int]()
_, err = repository.NewApplication(s.testDb).CreateApplication(
s.T().Context(),
s.appId,
fake.It[string](),
fake.It[string](),
appGroup.Id,
domain.ApplicationSystemType,
)
s.Require().NoError(err)
}
func (s *AccessListSuite) TestGetById_HappyPath() {
expectedAccessList := []entity.AccessList{
{
AppId: s.appId,
Method: fake.It[string](),
Value: false,
},
{
AppId: s.appId,
Method: fake.It[string](),
Value: true,
},
{
AppId: s.appId,
Method: fake.It[string](),
Value: true,
},
}
err := s.accessListRepo.InsertArrayAccessList(s.T().Context(), expectedAccessList)
s.Require().NoError(err)
req := domain.Identity{
Id: s.appId,
}
var accessList []domain.MethodInfo
err = s.api.Invoke("system/access_list/get_by_id").
JsonRequestBody(&req).
JsonResponseBody(&accessList).
Do(s.T().Context())
s.Require().NoError(err)
s.Require().Len(accessList, len(expectedAccessList))
actualAccessList := s.convertAccessList(accessList)
s.Require().ElementsMatch(expectedAccessList, actualAccessList)
}
func (s *AccessListSuite) TestSetOne_HappyPath() {
expectedAccessList := []entity.AccessList{
{
AppId: s.appId,
Method: fake.It[string](),
Value: false,
},
{
AppId: s.appId,
Method: fake.It[string](),
Value: true,
},
{
AppId: s.appId,
Method: fake.It[string](),
Value: true,
},
}
err := s.accessListRepo.InsertArrayAccessList(s.T().Context(), expectedAccessList)
s.Require().NoError(err)
req := domain.AccessListSetOneRequest{
AppId: s.appId,
Method: expectedAccessList[0].Method,
Value: true,
}
err = s.api.Invoke("system/access_list/set_one").
JsonRequestBody(&req).
Do(s.T().Context())
s.Require().NoError(err)
actualAccessList, err := s.accessListRepo.GetAccessListByAppId(s.T().Context(), s.appId)
s.Require().NoError(err)
for i := range expectedAccessList {
expectedAccessList[i].Value = true
}
s.Require().ElementsMatch(expectedAccessList, actualAccessList)
}
func (s *AccessListSuite) TestSetList_HappyPath() {
req := domain.AccessListSetListRequest{
AppId: s.appId,
Methods: []domain.MethodInfo{
{
Method: fake.It[string](),
Value: true,
},
{
Method: fake.It[string](),
Value: true,
},
},
}
err := s.api.Invoke("system/access_list/set_list").
JsonRequestBody(&req).
Do(s.T().Context())
s.Require().NoError(err)
actualAccessList, err := s.accessListRepo.GetAccessListByAppId(s.T().Context(), s.appId)
s.Require().NoError(err)
s.Require().Len(actualAccessList, len(req.Methods))
expectedAccessList := s.convertAccessList(req.Methods)
s.Require().ElementsMatch(expectedAccessList, actualAccessList)
}
func (s *AccessListSuite) TestDeleteList_HappyPath() {
accessList := []entity.AccessList{
{
AppId: s.appId,
Method: fake.It[string](),
Value: false,
},
{
AppId: s.appId,
Method: fake.It[string](),
Value: true,
},
{
AppId: s.appId,
Method: fake.It[string](),
Value: true,
},
}
err := s.accessListRepo.InsertArrayAccessList(s.T().Context(), accessList)
s.Require().NoError(err)
req := domain.AccessListDeleteListRequest{
AppId: s.appId,
Methods: []string{
accessList[0].Method,
accessList[1].Method,
},
}
err = s.api.Invoke("system/access_list/delete_list").
JsonRequestBody(&req).
Do(s.T().Context())
s.Require().NoError(err)
actualAccessList, err := s.accessListRepo.GetAccessListByAppId(s.T().Context(), s.appId)
s.Require().NoError(err)
s.Require().Len(actualAccessList, 1)
s.Require().Equal(accessList[2], actualAccessList[0])
}
func (s *AccessListSuite) convertAccessList(methods []domain.MethodInfo) []entity.AccessList {
converted := make([]entity.AccessList, 0, len(methods))
for _, method := range methods {
converted = append(converted, entity.AccessList{
AppId: s.appId,
Method: method.Method,
Value: method.Value,
})
}
return converted
}
+16 -13
View File
@@ -50,8 +50,7 @@ func (s *ApplicationSuite) SetupTest() {
} }
func (s *ApplicationSuite) TestGetAllApplications() { func (s *ApplicationSuite) TestGetAllApplications() {
toInsert := fake.It[[]domain.Application](fake.MaxSliceSize(2), fake.MinSliceSize(2)) expectedApps := s.insertApps(2)
expectedApps := s.insertApps(toInsert)
result := []domain.Application{} result := []domain.Application{}
err := s.api.Invoke("system/application/get_all"). err := s.api.Invoke("system/application/get_all").
@@ -114,7 +113,7 @@ func (s *ApplicationSuite) TestCreate_ApplicationNameNotUniqueInAppGroup() {
apiReq := fake.It[domain.CreateApplicationRequest]() apiReq := fake.It[domain.CreateApplicationRequest]()
apiReq.Type = domain.ApplicationSystemType apiReq.Type = domain.ApplicationSystemType
inserted := s.insertApps(fake.It[[]domain.Application](fake.MinSliceSize(1), fake.MaxSliceSize(1))) inserted := s.insertApps(1)
apiReq.ApplicationGroupId = inserted[0].ServiceId apiReq.ApplicationGroupId = inserted[0].ServiceId
apiReq.Name = inserted[0].Name apiReq.Name = inserted[0].Name
@@ -133,7 +132,7 @@ func (s *ApplicationSuite) TestCreate_ApplicationIdNotUnique() {
appGroup := s.createAppGroup() appGroup := s.createAppGroup()
apiReq.ApplicationGroupId = appGroup.Id apiReq.ApplicationGroupId = appGroup.Id
inserted := s.insertApps(fake.It[[]domain.Application](fake.MinSliceSize(1), fake.MaxSliceSize(1))) inserted := s.insertApps(1)
apiReq.Id = inserted[0].Id apiReq.Id = inserted[0].Id
err := s.api.Invoke("system/application/create_application"). err := s.api.Invoke("system/application/create_application").
@@ -145,7 +144,7 @@ func (s *ApplicationSuite) TestCreate_ApplicationIdNotUnique() {
} }
func (s *ApplicationSuite) TestUpdate_HappyPath() { func (s *ApplicationSuite) TestUpdate_HappyPath() {
inserted := s.insertApps(fake.It[[]domain.Application](fake.MinSliceSize(1), fake.MaxSliceSize(1))) inserted := s.insertApps(2)
apiReq := domain.UpdateApplicationRequest{ apiReq := domain.UpdateApplicationRequest{
OldId: inserted[0].Id, OldId: inserted[0].Id,
NewId: fake.It[int](), NewId: fake.It[int](),
@@ -196,7 +195,7 @@ func (s *ApplicationSuite) TestUpdate_HappyPath() {
} }
func (s *ApplicationSuite) TestUpdate_ApplicationNameNotUniqueInAppGroup() { func (s *ApplicationSuite) TestUpdate_ApplicationNameNotUniqueInAppGroup() {
inserted := s.insertApps(fake.It[[]domain.Application](fake.MinSliceSize(2), fake.MaxSliceSize(2))) inserted := s.insertApps(2)
apiReq := domain.UpdateApplicationRequest{ apiReq := domain.UpdateApplicationRequest{
NewId: inserted[0].Id, NewId: inserted[0].Id,
OldId: inserted[0].Id, OldId: inserted[0].Id,
@@ -213,7 +212,7 @@ func (s *ApplicationSuite) TestUpdate_ApplicationNameNotUniqueInAppGroup() {
} }
func (s *ApplicationSuite) TestUpdate_AppIdNotUnique() { func (s *ApplicationSuite) TestUpdate_AppIdNotUnique() {
inserted := s.insertApps(fake.It[[]domain.Application](fake.MinSliceSize(2), fake.MaxSliceSize(2))) inserted := s.insertApps(2)
apiReq := domain.UpdateApplicationRequest{ apiReq := domain.UpdateApplicationRequest{
OldId: inserted[0].Id, OldId: inserted[0].Id,
NewId: inserted[1].Id, NewId: inserted[1].Id,
@@ -246,8 +245,8 @@ func (s *ApplicationSuite) TestUpdate_AppNotFound() {
} }
func (s *ApplicationSuite) TestGetByToken() { func (s *ApplicationSuite) TestGetByToken() {
toInsert := fake.It[[]domain.Application](fake.MaxSliceSize(2), fake.MinSliceSize(2)) insertedApps := s.insertApps(2)
insertedApps := s.insertApps(toInsert)
token := fake.It[string]() token := fake.It[string]()
expectedApp := domain.GetApplicationByTokenResponse{ expectedApp := domain.GetApplicationByTokenResponse{
ApplicationId: insertedApps[0].Id, ApplicationId: insertedApps[0].Id,
@@ -266,8 +265,7 @@ func (s *ApplicationSuite) TestGetByToken() {
} }
func (s *ApplicationSuite) TestGetByToken_NotFound() { func (s *ApplicationSuite) TestGetByToken_NotFound() {
toInsert := fake.It[[]domain.Application](fake.MaxSliceSize(2), fake.MinSliceSize(2)) s.insertApps(2)
s.insertApps(toInsert)
result := domain.GetApplicationByTokenResponse{} result := domain.GetApplicationByTokenResponse{}
err := s.api.Invoke("system/application/get_application_by_token"). err := s.api.Invoke("system/application/get_application_by_token").
@@ -298,13 +296,18 @@ func (s *ApplicationSuite) createAppGroup() *entity.AppGroup {
return appGroup return appGroup
} }
func (s *ApplicationSuite) insertApps(toInsert []domain.Application) []domain.Application { func (s *ApplicationSuite) insertApps(appsCount uint) []domain.Application {
toInsert := fake.It[[]domain.Application](fake.MinSliceSize(appsCount), fake.MaxSliceSize(appsCount))
appGroup := s.createAppGroup() appGroup := s.createAppGroup()
toExpect := make([]domain.Application, 0, len(toInsert)) toExpect := make([]domain.Application, 0, len(toInsert))
for _, app := range toInsert { for _, app := range toInsert {
appId, err := s.appRepo.NextApplicationId(s.T().Context())
s.Require().NoError(err)
createdApp, err := s.appRepo.CreateApplication( createdApp, err := s.appRepo.CreateApplication(
s.T().Context(), s.T().Context(),
app.Id, appId,
app.Name, app.Name,
app.Description, app.Description,
appGroup.Id, appGroup.Id,
+18 -20
View File
@@ -12,7 +12,6 @@ import (
"isp-system-service/domain" "isp-system-service/domain"
"isp-system-service/entity" "isp-system-service/entity"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"github.com/txix-open/isp-kit/grpc/client" "github.com/txix-open/isp-kit/grpc/client"
"github.com/txix-open/isp-kit/test" "github.com/txix-open/isp-kit/test"
@@ -27,14 +26,13 @@ func TestSecureSuite(t *testing.T) {
type SecureSuite struct { type SecureSuite struct {
suite.Suite suite.Suite
test *test.Test test *test.Test
require *require.Assertions testDb *dbt.TestDb
testDb *dbt.TestDb api *client.Client
api *client.Client
} }
func (s *SecureSuite) SetupSuite() { func (s *SecureSuite) SetupSuite() {
s.test, s.require = test.New(s.T()) s.test, _ = test.New(s.T())
s.testDb = dbt.New(s.test, dbx.WithMigrationRunner("../migrations", s.test.Logger())) s.testDb = dbt.New(s.test, dbx.WithMigrationRunner("../migrations", s.test.Logger()))
@@ -66,8 +64,8 @@ func (s *SecureSuite) TestAuthenticate_Success() {
}). }).
JsonResponseBody(&result). JsonResponseBody(&result).
Do(context.Background()) Do(context.Background())
s.require.NoError(err) s.Require().NoError(err)
s.require.Equal(domain.AuthenticateResponse{ s.Require().Equal(domain.AuthenticateResponse{
Authenticated: true, Authenticated: true,
ErrorReason: "", ErrorReason: "",
AuthData: &domain.AuthData{ AuthData: &domain.AuthData{
@@ -87,8 +85,8 @@ func (s *SecureSuite) TestAuthenticate_NotFound() {
}). }).
JsonResponseBody(&result). JsonResponseBody(&result).
Do(context.Background()) Do(context.Background())
s.require.NoError(err) s.Require().NoError(err)
s.require.Equal(domain.AuthenticateResponse{ s.Require().Equal(domain.AuthenticateResponse{
Authenticated: false, Authenticated: false,
ErrorReason: domain.ErrTokenNotFound.Error(), ErrorReason: domain.ErrTokenNotFound.Error(),
AuthData: nil, AuthData: nil,
@@ -107,8 +105,8 @@ func (s *SecureSuite) TestAuthenticate_NotExpired() {
}). }).
JsonResponseBody(&result). JsonResponseBody(&result).
Do(context.Background()) Do(context.Background())
s.require.NoError(err) s.Require().NoError(err)
s.require.Equal(domain.AuthenticateResponse{ s.Require().Equal(domain.AuthenticateResponse{
Authenticated: true, Authenticated: true,
ErrorReason: "", ErrorReason: "",
AuthData: &domain.AuthData{ AuthData: &domain.AuthData{
@@ -132,8 +130,8 @@ func (s *SecureSuite) TestAuthenticate_Expired() {
}). }).
JsonResponseBody(&result). JsonResponseBody(&result).
Do(context.Background()) Do(context.Background())
s.require.NoError(err) s.Require().NoError(err)
s.require.Equal(domain.AuthenticateResponse{ s.Require().Equal(domain.AuthenticateResponse{
Authenticated: false, Authenticated: false,
ErrorReason: domain.ErrTokenExpired.Error(), ErrorReason: domain.ErrTokenExpired.Error(),
AuthData: nil, AuthData: nil,
@@ -155,8 +153,8 @@ func (s *SecureSuite) TestAuthorize_Success_True() {
}). }).
JsonResponseBody(&result). JsonResponseBody(&result).
Do(context.Background()) Do(context.Background())
s.require.NoError(err) s.Require().NoError(err)
s.require.Equal(domain.AuthorizeResponse{ s.Require().Equal(domain.AuthorizeResponse{
Authorized: true, Authorized: true,
}, result) }, result)
} }
@@ -176,8 +174,8 @@ func (s *SecureSuite) TestAuthorize_Success_False() {
}). }).
JsonResponseBody(&result). JsonResponseBody(&result).
Do(context.Background()) Do(context.Background())
s.require.NoError(err) s.Require().NoError(err)
s.require.Equal(domain.AuthorizeResponse{ s.Require().Equal(domain.AuthorizeResponse{
Authorized: false, Authorized: false,
}, result) }, result)
} }
@@ -191,8 +189,8 @@ func (s *SecureSuite) TestAuthorize_NotFound() {
}). }).
JsonResponseBody(&result). JsonResponseBody(&result).
Do(context.Background()) Do(context.Background())
s.require.NoError(err) s.Require().NoError(err)
s.require.Equal(domain.AuthorizeResponse{ s.Require().Equal(domain.AuthorizeResponse{
Authorized: false, Authorized: false,
}, result) }, result)
} }