From 19ea238645e740db11102d4385777788cdf1f936 Mon Sep 17 00:00:00 2001 From: Danis Kirasirov <kirasirov@perx.ru> Date: Fri, 5 Apr 2024 10:41:56 +0000 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=20=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D0=BE=D0=B4=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20Organization=20=D0=B4=D0=BB=D1=8F=20=D0=BE?= =?UTF-8?q?=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=B0=20System,=20=D0=BA=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D1=8B=D0=B9=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D0=B7=D1=83=D0=B5=D1=82=D1=81=D1=8F=20=D0=B2=20=D1=88?= =?UTF-8?q?=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/template/builder.go | 13 ++++--------- pkg/template/builder_test.go | 21 --------------------- pkg/template/system.go | 24 ------------------------ 3 files changed, 4 insertions(+), 54 deletions(-) diff --git a/pkg/template/builder.go b/pkg/template/builder.go index b1414df2..64530be6 100644 --- a/pkg/template/builder.go +++ b/pkg/template/builder.go @@ -5,17 +5,14 @@ import ( "context" "text/template" - "git.perx.ru/perxis/perxis-go/pkg/account" "git.perx.ru/perxis/perxis-go/pkg/collections" "git.perx.ru/perxis/perxis-go/pkg/content" "git.perx.ru/perxis/perxis-go/pkg/environments" - "git.perx.ru/perxis/perxis-go/pkg/organizations" "git.perx.ru/perxis/perxis-go/pkg/spaces" ) type Builder struct { ctx context.Context - acc *account.Account cnt *content.Content SpaceID string EnvID string @@ -23,16 +20,14 @@ type Builder struct { data map[string]interface{} // Для кеширования запросов - space *spaces.Space - environment *environments.Environment - collection *collections.Collection - organization *organizations.Organization + space *spaces.Space + environment *environments.Environment + collection *collections.Collection } -func NewBuilder(acc *account.Account, cnt *content.Content, space, env, col string) *Builder { +func NewBuilder(cnt *content.Content, space, env, col string) *Builder { return &Builder{ ctx: context.Background(), - acc: acc, cnt: cnt, SpaceID: space, EnvID: env, diff --git a/pkg/template/builder_test.go b/pkg/template/builder_test.go index f9e7b0a6..128f7064 100644 --- a/pkg/template/builder_test.go +++ b/pkg/template/builder_test.go @@ -5,7 +5,6 @@ import ( "errors" "testing" - "git.perx.ru/perxis/perxis-go/pkg/account" "git.perx.ru/perxis/perxis-go/pkg/collections" colsmocks "git.perx.ru/perxis/perxis-go/pkg/collections/mocks" "git.perx.ru/perxis/perxis-go/pkg/content" @@ -13,8 +12,6 @@ import ( envsmocks "git.perx.ru/perxis/perxis-go/pkg/environments/mocks" "git.perx.ru/perxis/perxis-go/pkg/items" mocksitems "git.perx.ru/perxis/perxis-go/pkg/items/mocks" - "git.perx.ru/perxis/perxis-go/pkg/organizations" - orgsmocks "git.perx.ru/perxis/perxis-go/pkg/organizations/mocks" "git.perx.ru/perxis/perxis-go/pkg/spaces" spsmocks "git.perx.ru/perxis/perxis-go/pkg/spaces/mocks" "github.com/stretchr/testify/assert" @@ -31,7 +28,6 @@ func TestBuilder_Execute(t *testing.T) { want any wantErr bool - getAcc func() (acc *account.Account, assertExpectations func(t *testing.T)) getCnt func() (cnt *content.Content, assertExpectations func(t *testing.T)) }{ {name: "error", str: "hello {{ .a }}", data: "world", want: "", wantErr: true}, @@ -100,15 +96,6 @@ func TestBuilder_Execute(t *testing.T) { }}, {name: "lookup without itemID", SpaceID: "space", EnvID: "env", str: "hello {{ lookup \"secrets.pass\" }}", data: "", want: "", wantErr: true}, {name: "system#1", SpaceID: "space", str: "hello {{ system.SpaceID }}", data: "", want: "hello space", wantErr: false}, - {name: "system organization", SpaceID: "space", EnvID: "env", getCnt: func() (cnt *content.Content, assertExpectations func(t *testing.T)) { - spsSvc := &spsmocks.Spaces{} - spsSvc.On("Get", context.Background(), "space").Return(&spaces.Space{OrgID: "orgid"}, nil).Once() - return &content.Content{Spaces: spsSvc}, func(t *testing.T) { spsSvc.AssertExpectations(t) } - }, getAcc: func() (acc *account.Account, assertExpectations func(t *testing.T)) { - orgsSvc := &orgsmocks.Organizations{} - orgsSvc.On("Get", context.Background(), "orgid").Return(&organizations.Organization{Name: "Org"}, nil).Once() - return &account.Account{Organizations: orgsSvc}, func(t *testing.T) { orgsSvc.AssertExpectations(t) } - }, str: "hello {{ system.Organization.Name }}", want: "hello Org", wantErr: false}, {name: "system space", SpaceID: "space", getCnt: func() (cnt *content.Content, assertExpectations func(t *testing.T)) { spsSvc := &spsmocks.Spaces{} spsSvc.On("Get", context.Background(), "space").Return(&spaces.Space{Description: "description"}, nil).Once() @@ -128,14 +115,7 @@ func TestBuilder_Execute(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - var acc *account.Account var cnt *content.Content - - if tt.getAcc != nil { - var checkFn func(*testing.T) - acc, checkFn = tt.getAcc() - defer checkFn(t) - } if tt.getCnt != nil { var checkFn func(*testing.T) cnt, checkFn = tt.getCnt() @@ -144,7 +124,6 @@ func TestBuilder_Execute(t *testing.T) { b := &Builder{ ctx: context.Background(), - acc: acc, cnt: cnt, SpaceID: tt.SpaceID, EnvID: tt.EnvID, diff --git a/pkg/template/system.go b/pkg/template/system.go index 48b464e4..c7dda43f 100644 --- a/pkg/template/system.go +++ b/pkg/template/system.go @@ -3,7 +3,6 @@ package template import ( "git.perx.ru/perxis/perxis-go/pkg/collections" "git.perx.ru/perxis/perxis-go/pkg/environments" - "git.perx.ru/perxis/perxis-go/pkg/organizations" "git.perx.ru/perxis/perxis-go/pkg/spaces" ) @@ -23,14 +22,6 @@ func (s *System) CollectionID() string { return s.builder.CollID } -func (s *System) OrganizationID() (string, error) { - org, err := s.Organization() - if err != nil { - return "", err - } - return org.ID, nil -} - func (s *System) Space() (*spaces.Space, error) { if s.builder.space != nil { return s.builder.space, nil @@ -60,18 +51,3 @@ func (s *System) Collection() (*collections.Collection, error) { s.builder.collection = coll return s.builder.collection, err } - -func (s *System) Organization() (*organizations.Organization, error) { - if s.builder.organization != nil { - return s.builder.organization, nil - } - - sp, err := s.Space() - if err != nil { - return nil, err - } - - org, err := s.builder.acc.Organizations.Get(s.builder.ctx, sp.OrgID) - s.builder.organization = org - return s.builder.organization, err -} -- GitLab