Skip to content
Snippets Groups Projects
Select Git revision
1 result Searching

server_test.go

  • setup.go 5.05 KiB
    package setup
    
    import (
    	"context"
    
    	"git.perx.ru/perxis/perxis-go/pkg/clients"
    	"git.perx.ru/perxis/perxis-go/pkg/collections"
    	"git.perx.ru/perxis/perxis-go/pkg/content"
    	"git.perx.ru/perxis/perxis-go/pkg/items"
    	"git.perx.ru/perxis/perxis-go/pkg/roles"
    	"go.uber.org/zap"
    )
    
    // Setup реализует процесс настройки пространства. Указав необходимые требования к конфигурации пространства можно
    // выполнить процесс установки, проверки и удаления требований.
    type Setup struct {
    	SpaceID       string
    	EnvironmentID string
    
    	Roles       []RoleConfig
    	Clients     []ClientConfig
    	Collections []CollectionConfig
    	Items       []ItemConfig
    
    	content *content.Content
    
    	force  bool
    	remove bool
    
    	errors []error
    	logger *zap.Logger
    }
    
    func NewSetup(content *content.Content, spaceID, environmentID string, logger *zap.Logger) *Setup {
    	//logger = logger.With(zap.String("Space", spaceID), zap.String("Environment", environmentID))
    
    	if logger == nil {
    		logger = zap.NewNop()
    	}
    
    	return &Setup{
    		SpaceID:       spaceID,
    		EnvironmentID: environmentID,
    		content:       content,
    		logger:        logger,
    	}
    }
    
    func (s *Setup) WithForce(force bool) *Setup {
    	setup := *s
    	setup.force = force
    	return &setup
    }
    
    func (s *Setup) IsForce() bool {
    	return s.force
    }
    
    func (s *Setup) WithRemove(remove bool) *Setup {
    	setup := *s
    	setup.remove = remove
    	return &setup
    }
    
    func (s *Setup) IsRemove() bool {
    	return s.remove
    }
    
    func (s *Setup) HasErrors() bool {
    	return len(s.errors) > 0