componentizer

package module
v0.0.0-...-dd94429 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2020 License: MIT Imports: 23 Imported by: 0

README

componentizer

Go library enabling to build component-based models.

Documentation

Index

Constants

View Source
const (
	//GitScm type of GIT source control management system
	GitScm SCMType = SCMType(SchemeGits)
	//SvnScm type of SVN source control management system
	SvnScm SCMType = SCMType(SchemeSvn)
	//UnknownScm represents an unknown source control management system
	UnknownScm SCMType = ""

	//SchemeFile  scheme for a file
	SchemeFile string = "file"
	//SchemeGits  scheme for Git
	SchemeGits string = "git"
	//SchemeSvn  scheme for svn
	SchemeSvn string = "svn"
	//SchemeHttp  scheme for http
	SchemeHttp string = "http"
	//SchemeHttps  scheme for https
	SchemeHttps string = "https"
)

Variables

This section is empty.

Functions

func DirExist

func DirExist(path string) bool

DirExist returns true if a directory corresponding to the given path exixts

func FileExist

func FileExist(path string) (bool, os.FileInfo)

FileExist returns true if a file corresponding to the given path exixts

Types

type Component

type Component interface {
	ComponentRef
	GetRepository() Repository
	GetTemplates() (bool, []string)
	ParseModel(path string, tplC TemplateContext) (Model, error)
	ParseComponents(path string, tplC TemplateContext) (Component, []Component, error)
}

type ComponentManager

type ComponentManager interface {
	//Init initialize the component manager with the specified main component
	Init(main Component, tplC TemplateContext) (Model, error)

	//ContainsFile returns paths pointing on templated components containing the given file
	//	Parameters
	//		name: the name of the file to search
	//		ctx: the context used to eventually template the matching components
	//		in: the component referencer where to look for the file, if not provided
	//          the Finder will look into all the components available into the platform.
	ContainsFile(name string, tplC TemplateContext, in ...ComponentRef) MatchingPaths

	//ContainsDirectory returns paths pointing on templated components containing the given directory
	//	Parameters
	//		name: the name of the directory to search
	//		ctx: the context used to eventually template the matching components
	//		in: the component referencer where to look for the directory, if not provided
	//          the Finder will look into all the components available into the platform.
	ContainsDirectory(name string, tplC TemplateContext, in ...ComponentRef) MatchingPaths

	//IsAvailable checks if a component is locally available
	IsAvailable(cr ComponentRef) bool

	// ComponentOrder returns a slice of component identifiers in the parsing order
	ComponentOrder() []string

	//Use returns a component matching the given reference.
	//If the component corresponding to the reference contains a template
	//definition then the component will be duplicated and templated before
	// being returned as a UsableComponent.
	// Don't forget to Release the UsableComponent once is processing is over...
	Use(cr ComponentRef, tplC TemplateContext) (UsableComponent, error)
}

ComponentManager is the facade for accessing components.

func CreateComponentManager

func CreateComponentManager(l *log.Logger, workDir string) ComponentManager

createComponentManager creates a new component manager

type ComponentRef

type ComponentRef interface {
	// ComponentId returns the referenced component id
	ComponentId() string
	// Component returns the referenced component
	Component(model interface{}) (Component, error)
}

ComponentRef allows to access to a component through its reference

type ComponentTester

type ComponentTester struct {
	// contains filtered or unexported fields
}

ComponentTester is an helper user to run unit tests based on local GIT repositories

func CreateComponentTester

func CreateComponentTester(ctx TestContext, tplC TemplateContext) *ComponentTester

CreateComponentTester creates a new ComponentTester

func (*ComponentTester) AssertComponentAvailable

func (t *ComponentTester) AssertComponentAvailable(refs ...string)

func (*ComponentTester) AssertComponentMissing

func (t *ComponentTester) AssertComponentMissing(refs ...string)

func (*ComponentTester) AssertComponentsExactly

func (t *ComponentTester) AssertComponentsExactly(refs ...string)

func (ComponentTester) AssertFile

func (t ComponentTester) AssertFile(u UsableComponent, file string)

AssertFile asserts that a usable component contains a specific file

func (ComponentTester) AssertFileContent

func (t ComponentTester) AssertFileContent(u UsableComponent, file, desiredContent string)

AssertFileContent asserts that a usable component contains a specific file with the desired content

func (*ComponentTester) Clean

func (t *ComponentTester) Clean()

Clean deletes all the content created locally during a test

func (*ComponentTester) ComponentCount

func (t *ComponentTester) ComponentCount() int

ComponentCount returns the number of components available

func (*ComponentTester) ComponentManager

func (t *ComponentTester) ComponentManager() ComponentManager

func (*ComponentTester) CreateDir

func (t *ComponentTester) CreateDir(path string) *testRepo

CreateRep creates a new component folder corresponding to the given path

func (*ComponentTester) CreateDirEmptyDesc

func (t *ComponentTester) CreateDirEmptyDesc(path string) *testRepo

CreateRepDefaultDescriptor creates a new component folder corresponding to the given path and write into it an empty descriptor

func (*ComponentTester) Init

func (t *ComponentTester) Init(c Component) error

Init initializes the ComponentTester and build the environment bases on the launch context used during the tester's creation.

func (*ComponentTester) Model

func (t *ComponentTester) Model() Model

func (*ComponentTester) T

func (t *ComponentTester) T() *testing.T

func (*ComponentTester) TemplateContext

func (t *ComponentTester) TemplateContext() TemplateContext

type FileScmHandler

type FileScmHandler struct {
	Logger *log.Logger
}

FileScmHandler Represents the scm connector allowing to fetch local repositories.

It implements "github.com/ekara-platform/engine/component/scm.scmHandler

func (FileScmHandler) Fetch

func (fileScm FileScmHandler) Fetch(u *url.URL, path string, auth map[string]string) error

Fetch implements "github.com/ekara-platform/engine/component/scm.scmHandler

func (FileScmHandler) Matches

func (fileScm FileScmHandler) Matches(u *url.URL, path string) bool

Matches implements "github.com/ekara-platform/engine/component/scm.scmHandler

func (FileScmHandler) Switch

func (fileScm FileScmHandler) Switch(path string, ref string) error

Switch implements "github.com/ekara-platform/engine/component/scm.scmHandler

func (FileScmHandler) Update

func (fileScm FileScmHandler) Update(path string, auth map[string]string) error

Update implements "github.com/ekara-platform/engine/component/scm.scmHandler

type GitScmHandler

type GitScmHandler struct {
	Logger *log.Logger
}

GitScmHandler Represents the scm connector allowing to fecth GIT repositories.

It implements "github.com/ekara-platform/engine/component/scm.scmHandler

func (GitScmHandler) Fetch

func (gitScm GitScmHandler) Fetch(u *url.URL, path string, auth map[string]string) error

Fetch implements "github.com/ekara-platform/engine/component/scm.scmHandler

func (GitScmHandler) Matches

func (gitScm GitScmHandler) Matches(u *url.URL, path string) bool

Matches implements "github.com/ekara-platform/engine/component/scm.scmHandler

func (GitScmHandler) Switch

func (gitScm GitScmHandler) Switch(path string, ref string) error

Switch implements "github.com/ekara-platform/engine/component/scm.scmHandler

func (GitScmHandler) Update

func (gitScm GitScmHandler) Update(path string, auth map[string]string) error

Update implements "github.com/ekara-platform/engine/component/scm.scmHandler

type Handler

type Handler func() (fetchedComponent, error)

Handler allows to fetch a component.

If the component repository has already been fetched and if it matches then it will be updated, if not it will be fetched.

func GetScmHandler

func GetScmHandler(l *log.Logger, dir string, c Component) (Handler, error)

GetHandler returns an handler able to fetch a component

type MatchingPath

type MatchingPath interface {
	//Owner gives the usable component wherein the searched content has been located
	Owner() UsableComponent
	//RelativePath specifies the relatives path of the searched content into the usable component
	RelativePath() string
	//AbsolutePath specifies the absolute path of the searched content into the usable component
	AbsolutePath() string
}

MatchingPath represents the matching path of the searched content

type MatchingPaths

type MatchingPaths struct {
	//Paths holds the searched  results
	Paths []MatchingPath
}

MatchingPaths represents the matching paths of the searched content

func (MatchingPaths) Count

func (mp MatchingPaths) Count() int

Count returns the number of matching paths

func (MatchingPaths) JoinAbsolutePaths

func (mp MatchingPaths) JoinAbsolutePaths(separator string) string

JoinAbsolutePaths joins all the matching paths using the given separator

func (MatchingPaths) PrefixPaths

func (mp MatchingPaths) PrefixPaths(prefix string) []string

PrefixPaths returns the absolute mathcing paths prefixed with the given prefix

func (MatchingPaths) Release

func (mp MatchingPaths) Release()

Release deletes, if any, the templated paths returned

type Model

type Model interface {
	IsReferenced(c Component) bool
	Merge(with Model) (Model, error)
}

type Repository

type Repository struct {
	// Loc holds the absolute location of the repository
	Loc *url.URL
	// The reference to the branch or tag to fetch. If not specified the default branch will be fetched
	Ref string
	// The authentication parameters to use if repository is not publicly accessible
	Authentication map[string]string
}

Repository represents a component location

func CreateRepository

func CreateRepository(loc string, ref string, auth map[string]string) (Repository, error)

CreateRepository creates a repository

Parameters
	repo: the repository Url where to fetch the component
	ref: the ref to fetch, if the ref is not specified then the default branch will be fetched

func CreateTestRepository

func CreateTestRepository(path, ref string) Repository

func (Repository) CreateChildRepository

func (r Repository) CreateChildRepository(loc *url.URL, ref string, auth map[string]string) (Repository, error)

func (*Repository) Merge

func (r *Repository) Merge(with Repository)

func (Repository) String

func (r Repository) String() string

type SCMType

type SCMType string

SCMType represents a type of Source Control Management system

type TemplateContext

type TemplateContext interface {
	Clone(ref ComponentRef) TemplateContext
	Execute(content string) (string, error)
}

type TestContext

type TestContext struct {
	T              *testing.T
	Logger         *log.Logger
	Directory      string
	DescriptorName string
}

type UsableComponent

type UsableComponent interface {
	//Name returns the name of the component
	Id() string
	//Templated returns true is the component content has been templated
	Templated() bool
	//Release deletes the templated content.
	Release()
	//RootPath returns the absolute path of the, eventually templated, component
	RootPath() string
	//ContainsFile returns the matching path of the searched file
	ContainsFile(name string) (bool, MatchingPath)
	//ContainsDirectory returns the matching path of the searched directory
	ContainsDirectory(name string) (bool, MatchingPath)
	//Source returns the component that was used to produce this UsableComponent
	Source() ComponentRef
}

UsableComponent Represent a component which can be used physically

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL