-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_test.go
69 lines (55 loc) · 1.5 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"context"
"flag"
"fmt"
"os"
"testing"
"github.com/ONSdigital/dp-search-data-importer/features/steps"
dplogs "github.com/ONSdigital/log.go/v2/log"
"github.com/cucumber/godog"
"github.com/cucumber/godog/colors"
)
var componentFlag = flag.Bool("component", false, "perform component tests")
type ComponentTest struct {
t *testing.T
}
func (f *ComponentTest) InitializeScenario(ctx *godog.ScenarioContext) {
component := steps.NewComponent(f.t)
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
if err := component.Reset(); err != nil {
return ctx, fmt.Errorf("unable to initialise scenario: %s", err)
}
return ctx, nil
})
ctx.After(func(ctx context.Context, sc *godog.Scenario, err error) (context.Context, error) {
component.Close()
return ctx, nil
})
component.RegisterSteps(ctx)
}
func (f *ComponentTest) InitializeTestSuite(ctx *godog.TestSuiteContext) {
dplogs.Namespace = "dp-search-data-importer"
}
func TestComponent(t *testing.T) {
if *componentFlag {
status := 0
var opts = godog.Options{
Output: colors.Colored(os.Stdout),
Format: "pretty",
Paths: flag.Args(),
}
f := &ComponentTest{t: t}
status = godog.TestSuite{
Name: "feature_tests",
ScenarioInitializer: f.InitializeScenario,
TestSuiteInitializer: f.InitializeTestSuite,
Options: &opts,
}.Run()
if status > 0 {
t.Fail()
}
} else {
t.Skip("component flag required to run component tests")
}
}