diff --git a/pkg/template/builder.go b/pkg/template/builder.go index b1414df21adc6373a4dcd75460991f782e7eaab9..64530be62337de21dc5b93956df261ce5211a302 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 f9e7b0a66b7b4ec54f9151136ed0e60d7f386cb9..128f706423f3ecc67097a76b8926fbed619eb1ce 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 48b464e4cf106f5e90dfc622764391080646ec10..c7dda43f08c852f590cd7cfa16ec00709423c7a3 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 -}