2019-11-02 14:32:58 +00:00
|
|
|
package suites
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// Suite the definition of a suite.
|
2019-11-02 14:32:58 +00:00
|
|
|
type Suite struct {
|
2020-03-03 07:18:25 +00:00
|
|
|
SetUp func(tmpPath string) error
|
|
|
|
SetUpTimeout time.Duration
|
|
|
|
|
|
|
|
// Callback called when an error occur during setup phase.
|
2019-11-30 16:49:52 +00:00
|
|
|
OnSetupTimeout func() error
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// Callback called when at least one test fail.
|
2020-03-03 07:18:25 +00:00
|
|
|
OnError func() error
|
|
|
|
|
2019-11-30 16:49:52 +00:00
|
|
|
TestTimeout time.Duration
|
|
|
|
|
2019-11-02 14:32:58 +00:00
|
|
|
TearDown func(tmpPath string) error
|
|
|
|
TearDownTimeout time.Duration
|
|
|
|
|
|
|
|
// A textual description of the suite purpose.
|
|
|
|
Description string
|
|
|
|
}
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// Registry represent a registry of suite by name.
|
2019-11-02 14:32:58 +00:00
|
|
|
type Registry struct {
|
|
|
|
registry map[string]Suite
|
|
|
|
}
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// GlobalRegistry a global registry used by Authelia tooling.
|
2019-11-02 14:32:58 +00:00
|
|
|
var GlobalRegistry *Registry
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
GlobalRegistry = NewSuitesRegistry()
|
|
|
|
}
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// NewSuitesRegistry create a suites registry.
|
2019-11-02 14:32:58 +00:00
|
|
|
func NewSuitesRegistry() *Registry {
|
|
|
|
return &Registry{make(map[string]Suite)}
|
|
|
|
}
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// Register register a suite by name.
|
2019-11-02 14:32:58 +00:00
|
|
|
func (sr *Registry) Register(name string, suite Suite) {
|
|
|
|
if _, found := sr.registry[name]; found {
|
|
|
|
log.Fatal(fmt.Sprintf("Trying to register the suite %s multiple times", name))
|
|
|
|
}
|
|
|
|
sr.registry[name] = suite
|
|
|
|
}
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// Get return a suite by name.
|
2019-11-02 14:32:58 +00:00
|
|
|
func (sr *Registry) Get(name string) Suite {
|
|
|
|
s, found := sr.registry[name]
|
|
|
|
if !found {
|
|
|
|
log.Fatal(fmt.Sprintf("The suite %s does not exist", name))
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2020-05-02 05:06:39 +00:00
|
|
|
// Suites list available suites.
|
2019-11-02 14:32:58 +00:00
|
|
|
func (sr *Registry) Suites() []string {
|
|
|
|
suites := make([]string, 0)
|
|
|
|
for k := range sr.registry {
|
|
|
|
suites = append(suites, k)
|
|
|
|
}
|
|
|
|
return suites
|
|
|
|
}
|