Skip to content
Snippets Groups Projects
Commit 2896c032 authored by Pavel Antonov's avatar Pavel Antonov :asterisk:
Browse files

Merge branch 'feature/PRXS-1813-2306-RemoveTemplatesOrganization' into 'master'

Удален метод получения Organization для объекта System, который используется в шаблонах

See merge request perxis/perxis-go!209
parents ba6ead1a 19ea2386
No related branches found
No related tags found
No related merge requests found
......@@ -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,
......
......@@ -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,
......
......@@ -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
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment