This repository has been archived by the owner on Sep 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
autodiscover_test.go
701 lines (597 loc) · 19.9 KB
/
autodiscover_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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.
package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"testing"
"text/template"
"time"
"github.com/cenkalti/backoff/v4"
"github.com/cucumber/godog"
"github.com/cucumber/godog/colors"
apme2e "github.com/elastic/e2e-testing/internal"
log "github.com/sirupsen/logrus"
flag "github.com/spf13/pflag"
"go.elastic.co/apm/v2"
"github.com/elastic/e2e-testing/internal/common"
"github.com/elastic/e2e-testing/internal/config"
"github.com/elastic/e2e-testing/internal/deploy"
"github.com/elastic/e2e-testing/internal/kubernetes"
"github.com/elastic/e2e-testing/internal/shell"
"github.com/elastic/e2e-testing/internal/utils"
"github.com/elastic/e2e-testing/pkg/downloads"
)
var beatVersions = map[string]string{}
var defaultEventsWaitTimeout = 300 * time.Second
var defaultDeployWaitTimeout = 300 * time.Second
var tx *apm.Transaction
var stepSpan *apm.Span
type podsManager struct {
kubectl kubernetes.Control
ctx context.Context
}
func (m *podsManager) executeTemplateFor(podName string, writer io.Writer, options []string) error {
span, _ := apm.StartSpanOptions(m.ctx, "Executing template for pod", "pod.template.execute", apm.SpanOptions{
Parent: apm.SpanFromContext(m.ctx).TraceContext(),
})
span.Context.SetLabel("pod", podName)
span.Context.SetLabel("options", options)
defer span.End()
path := filepath.Join("testdata/templates", sanitizeName(podName)+".yml.tmpl")
err := m.configureDockerImage(podName)
if err != nil {
return err
}
usedOptions := make(map[string]bool)
funcs := template.FuncMap{
"option": func(o string) bool {
usedOptions[o] = true
for _, option := range options {
if o == option {
return true
}
}
return false
},
"beats_namespace": func() string {
return deploy.GetDockerNamespaceEnvVarForRepository(podName, "beats")
},
"beats_version": func() string {
return beatVersions[podName]
},
"namespace": func() string {
return m.kubectl.Namespace
},
// Can be used to add owner references so cluster-level resources
// are removed when removing the namespace.
"namespace_uid": func() string {
return m.kubectl.NamespaceUID
},
}
t, err := template.New(filepath.Base(path)).Funcs(funcs).ParseFiles(path)
if os.IsNotExist(err) {
log.Debugf("template %s does not exist", path)
return godog.ErrPending
}
if err != nil {
return fmt.Errorf("parsing template %s: %w", path, err)
}
err = t.ExecuteTemplate(writer, filepath.Base(path), nil)
if err != nil {
return fmt.Errorf("executing template %s: %w", path, err)
}
for _, option := range options {
if _, used := usedOptions[option]; !used {
log.Debugf("option '%s' is not used in template for '%s'", option, podName)
return godog.ErrPending
}
}
return nil
}
func (m *podsManager) configureDockerImage(podName string) error {
namespace := "beats"
if podName != "filebeat" && podName != "heartbeat" && podName != "metricbeat" && podName != "elastic-agent" && podName != "elasticsearch" {
log.Debugf("Not processing custom binaries for pod: %s. Only [elasticsearch, filebeat, heartbeat, metricbeat, elastic-agent] will be processed", podName)
return nil
}
span, _ := apm.StartSpanOptions(m.ctx, "Configuring Docker image", "pod.docker-image.configure", apm.SpanOptions{
Parent: apm.SpanFromContext(m.ctx).TraceContext(),
})
span.Context.SetLabel("pod", podName)
defer span.End()
// we are caching the versions by pod to avoid downloading and loading/tagging the Docker image multiple times
if beatVersions[podName] != "" {
log.Tracef("The beat version was already loaded: %s", beatVersions[podName])
return nil
}
v := common.BeatVersion
if strings.EqualFold(podName, "elastic-agent") {
v = common.ElasticAgentVersion
}
beatVersion := downloads.GetSnapshotVersion(v) + "-amd64"
ciSnapshotsFn := downloads.UseBeatsCISnapshots
if strings.EqualFold(podName, "elastic-agent") {
ciSnapshotsFn = downloads.UseElasticAgentCISnapshots
} else if strings.EqualFold(podName, "elasticsearch") {
// never process elasticsearch artifacts from CI artifacts
ciSnapshotsFn = func() bool { return false }
}
if ciSnapshotsFn() {
log.Debugf("Configuring Docker image for %s", podName)
_, imagePath, err := downloads.FetchElasticArtifact(m.ctx, podName, v, "linux", "amd64", "tar.gz", true, true)
if err != nil {
return err
}
// load the TAR file into the docker host as a Docker image
err = deploy.LoadImage(imagePath)
if err != nil {
return err
}
if podName == "elasticsearch" {
namespace = "elasticsearch"
}
err = deploy.TagImage(
"docker.elastic.co/"+namespace+"/"+podName+":"+downloads.GetSnapshotVersion(common.BeatVersionBase),
"docker.elastic.co/observability-ci/"+podName+":"+beatVersion,
)
if err != nil {
return err
}
// load PR image into kind
err = cluster.LoadImage(m.ctx, "docker.elastic.co/observability-ci/"+podName+":"+beatVersion)
if err != nil {
return err
}
}
log.Tracef("Caching beat version '%s' for %s", beatVersion, podName)
beatVersions[podName] = beatVersion
return nil
}
func (m *podsManager) isDeleted(podName string, options []string) error {
var buf bytes.Buffer
err := m.executeTemplateFor(podName, &buf, options)
if err != nil {
return err
}
_, err = m.kubectl.RunWithStdin(m.ctx, &buf, "delete", "-f", "-")
if err != nil {
return fmt.Errorf("failed to delete '%s': %w", podName, err)
}
return nil
}
func (m *podsManager) isDeployed(podName string, options []string) error {
var buf bytes.Buffer
err := m.executeTemplateFor(podName, &buf, options)
if err != nil {
return err
}
_, err = m.kubectl.RunWithStdin(m.ctx, &buf, "apply", "-f", "-")
if err != nil {
return fmt.Errorf("failed to deploy '%s': %w", podName, err)
}
return nil
}
func (m *podsManager) isRunning(podName string, options []string) error {
err := m.isDeployed(podName, options)
if err != nil {
return err
}
ctx, cancel := context.WithTimeout(m.ctx, defaultDeployWaitTimeout)
defer cancel()
_, err = m.getPodInstances(ctx, podName)
if err != nil {
return fmt.Errorf("waiting for instance of '%s': %w", podName, err)
}
return nil
}
func (m *podsManager) resourceIs(podName string, state string, options ...string) error {
span, _ := apm.StartSpanOptions(m.ctx, "Checking resource state", "pod.state.check", apm.SpanOptions{
Parent: apm.SpanFromContext(m.ctx).TraceContext(),
})
span.Context.SetLabel("options", options)
span.Context.SetLabel("pod", podName)
span.Context.SetLabel("state", state)
defer span.End()
switch state {
case "running":
return m.isRunning(podName, options)
case "deployed":
return m.isDeployed(podName, options)
case "deleted":
return m.isDeleted(podName, options)
default:
return godog.ErrPending
}
}
func (m *podsManager) startEphemeralContainerIn(podName string) error {
podName = sanitizeName(podName)
// https://kubernetes.io/docs/tasks/debug/debug-application/debug-running-pod/#ephemeral-container-example
// example: kubectl debug -it #{podName} -c ephemeral-container --image=busybox:1.28 -- /bin/sh -c "echo Hi from an ephemeral container"
_, err := m.kubectl.Run(
m.ctx,
"debug",
"-it",
podName,
"-c",
"ephemeral-container",
"--image=busybox:1.28",
"--",
"/bin/sh", "-c",
"echo Hi from an ephemeral container")
if err != nil {
return fmt.Errorf("failed to create ephemeral container: %w. Is EphemeralContainers feature flag enabled in the cluster?", err)
}
return nil
}
func (m *podsManager) collectsEventsWith(podName string, condition string) error {
_, _, ok := splitCondition(condition)
if !ok {
return fmt.Errorf("invalid condition '%s'", condition)
}
return m.waitForEventsCondition(podName, func(ctx context.Context, localPath string) (bool, error) {
ok, err := containsEventsWith(m.ctx, localPath, condition)
if ok {
return true, nil
}
if err != nil {
log.Debugf("Error checking if %v contains %v: %v", localPath, condition, err)
}
return false, nil
})
}
func (m *podsManager) doesNotCollectEvents(podName, condition, duration string) error {
_, _, ok := splitCondition(condition)
if !ok {
return fmt.Errorf("invalid condition '%s'", condition)
}
d, err := time.ParseDuration(duration)
if err != nil {
return fmt.Errorf("invalid duration %s: %w", d, err)
}
return m.waitForEventsCondition(podName, func(ctx context.Context, localPath string) (bool, error) {
events, err := readEventsWith(m.ctx, localPath, condition)
if err != nil {
return false, err
}
// No events ever received, so condition satisfied.
if len(events) == 0 {
return true, nil
}
lastEvent := events[len(events)-1]
lastTimestamp, ok := lastEvent["@timestamp"].(string)
if !ok {
return false, fmt.Errorf("event %v doesn't contain a @timestamp", lastEvent)
}
t, err := time.Parse(time.RFC3339, lastTimestamp)
if err != nil {
return false, fmt.Errorf("failed to parse @timestamp %s: %w", lastTimestamp, err)
}
if sinceLast := time.Now().Sub(t); sinceLast <= d {
// Condition cannot be satisfied until the duration has passed after the last
// event. So wait till then.
select {
case <-ctx.Done():
case <-time.After(d - sinceLast):
}
return false, nil
}
return true, nil
})
}
func (m *podsManager) waitForEventsCondition(podName string, conditionFn func(ctx context.Context, localPath string) (bool, error)) error {
span, _ := apm.StartSpanOptions(m.ctx, "Waiting for events conditions", "pod.events.waitForCondition", apm.SpanOptions{
Parent: apm.SpanFromContext(m.ctx).TraceContext(),
})
span.Context.SetLabel("pod", podName)
defer span.End()
ctx, cancel := context.WithTimeout(m.ctx, defaultEventsWaitTimeout)
defer cancel()
instances, err := m.getPodInstances(ctx, podName)
if err != nil {
return fmt.Errorf("failed to get pod name: %w", err)
}
tmpDir, err := os.MkdirTemp(os.TempDir(), "test-")
if err != nil {
return fmt.Errorf("failed to create temporary directory: %w", err)
}
defer os.RemoveAll(tmpDir)
containerPath := fmt.Sprintf("%s/%s:/tmp/beats-events", m.kubectl.Namespace, instances[0])
localPath := filepath.Join(tmpDir, "events")
exp := backoff.WithContext(backoff.NewConstantBackOff(10*time.Second), ctx)
return backoff.Retry(func() error {
err := m.copyEvents(ctx, containerPath, localPath)
if err != nil {
return fmt.Errorf("failed to copy events from %s: %w", containerPath, err)
}
ok, err := conditionFn(ctx, localPath)
if err != nil {
return fmt.Errorf("events condition failed: %w", err)
}
if !ok {
return fmt.Errorf("events do not satisfy condition")
}
return nil
}, exp)
}
func (m *podsManager) copyEvents(ctx context.Context, containerPath string, localPath string) error {
today := time.Now().Format("20060102")
paths := []string{
containerPath,
// Format used since 8.0.
containerPath + "-" + today + ".ndjson",
}
var err error
var output string
for _, containerPath := range paths {
// This command always succeeds, so check if the local path has been created.
os.Remove(localPath)
output, _ = m.kubectl.Run(ctx, "cp", "--no-preserve", containerPath, localPath)
if _, err = os.Stat(localPath); os.IsNotExist(err) {
continue
}
return nil
}
log.Debugf("Failed to copy events from %s to %s: %s", containerPath, localPath, output)
return err
}
func (m *podsManager) getPodInstances(ctx context.Context, podName string) (instances []string, err error) {
span, _ := apm.StartSpanOptions(m.ctx, "Getting pod instances", "pod.instances.get", apm.SpanOptions{
Parent: apm.SpanFromContext(m.ctx).TraceContext(),
})
span.Context.SetLabel("pod", podName)
defer span.End()
app := sanitizeName(podName)
ticker := backoff.WithContext(backoff.NewConstantBackOff(10*time.Second), ctx)
err = backoff.Retry(func() error {
output, err := m.kubectl.Run(ctx, "get", "pods",
"-l", "k8s-app="+app,
"--template", `{{range .items}}{{ if eq .status.phase "Running" }}{{.metadata.name}}{{"\n"}}{{ end }}{{end}}`)
if err != nil {
return err
}
if output == "" {
return fmt.Errorf("no running pods with label k8s-app=%s found", app)
}
instances = strings.Split(strings.TrimSpace(output), "\n")
return nil
}, ticker)
return
}
func splitCondition(c string) (key string, value string, ok bool) {
fields := strings.SplitN(c, ":", 2)
if len(fields) != 2 || len(fields[0]) == 0 {
return
}
return fields[0], fields[1], true
}
func flattenMap(m map[string]interface{}) map[string]interface{} {
flattened := make(map[string]interface{})
for k, v := range m {
switch child := v.(type) {
case map[string]interface{}:
childMap := flattenMap(child)
for ck, cv := range childMap {
flattened[k+"."+ck] = cv
}
default:
flattened[k] = v
}
}
return flattened
}
func containsEventsWith(ctx context.Context, path string, condition string) (bool, error) {
events, err := readEventsWith(ctx, path, condition)
if err != nil {
return false, err
}
return len(events) > 0, nil
}
func readEventsWith(ctx context.Context, path string, condition string) ([]map[string]interface{}, error) {
span, _ := apm.StartSpanOptions(ctx, "Reading events", "kubernetes.events.read", apm.SpanOptions{
Parent: apm.SpanFromContext(ctx).TraceContext(),
})
span.Context.SetLabel("condition", condition)
span.Context.SetLabel("path", path)
defer span.End()
key, value, ok := splitCondition(condition)
if !ok {
return nil, fmt.Errorf("invalid condition '%s'", condition)
}
f, err := os.Open(path)
if err != nil {
return nil, fmt.Errorf("opening %s: %w", path, err)
}
defer f.Close()
var events []map[string]interface{}
decoder := json.NewDecoder(f)
for decoder.More() {
var event map[string]interface{}
err := decoder.Decode(&event)
if err == io.EOF {
break
}
if err != nil {
return nil, fmt.Errorf("decoding event: %w", err)
}
event = flattenMap(event)
if v, ok := event[key]; ok && fmt.Sprint(v) == value {
events = append(events, event)
}
}
return events, nil
}
func sanitizeName(name string) string {
return strings.ReplaceAll(strings.ToLower(name), " ", "-")
}
func waitDuration(ctx context.Context, duration string) error {
d, err := time.ParseDuration(duration)
if err != nil {
return fmt.Errorf("invalid duration %s: %w", d, err)
}
select {
case <-time.After(d):
case <-ctx.Done():
}
return nil
}
var cluster kubernetes.Cluster
func InitializeTestSuite(ctx *godog.TestSuiteContext) {
suiteContext, cancel := context.WithCancel(context.Background())
log.DeferExitHandler(cancel)
ctx.BeforeSuite(func() {
// init logger
config.Init()
common.InitVersions()
defaultEventsWaitTimeout = defaultEventsWaitTimeout * time.Duration(utils.TimeoutFactor)
defaultDeployWaitTimeout = defaultDeployWaitTimeout * time.Duration(utils.TimeoutFactor)
var suiteTx *apm.Transaction
var suiteParentSpan *apm.Span
// instrumentation
defer apm.DefaultTracer().Flush(nil)
suiteTx = apme2e.StartTransaction("Initialise k8s Autodiscover", "test.suite")
defer suiteTx.End()
suiteParentSpan = suiteTx.StartSpan("Before k8s Autodiscover test suite", "test.suite.before", nil)
suiteContext = apm.ContextWithSpan(suiteContext, suiteParentSpan)
defer suiteParentSpan.End()
err := cluster.Initialize(suiteContext, "testdata/kind.yml")
if err != nil {
e := apm.DefaultTracer().NewError(err)
e.Send()
log.WithError(err).Fatal("Failed to initialize cluster")
}
log.DeferExitHandler(func() {
cluster.Cleanup(suiteContext)
})
})
ctx.AfterSuite(func() {
f := func() {
apm.DefaultTracer().Flush(nil)
}
defer f()
// instrumentation
var suiteTx *apm.Transaction
var suiteParentSpan *apm.Span
defer apm.DefaultTracer().Flush(nil)
suiteTx = apme2e.StartTransaction("Tear Down k8s Autodiscover", "test.suite")
defer suiteTx.End()
suiteParentSpan = suiteTx.StartSpan("After k8s Autodiscover test suite", "test.suite.after", nil)
suiteContext = apm.ContextWithSpan(suiteContext, suiteParentSpan)
defer suiteParentSpan.End()
// store cluster logs: see https://kind.sigs.k8s.io/docs/user/quick-start/#exporting-cluster-logs
clusterName := cluster.Name()
logsPath, _ := filepath.Abs(filepath.Join("..", "..", "..", "outputs", "kubernetes-autodiscover", clusterName))
_, err := shell.Execute(suiteContext, ".", "kind", "export", "logs", "--name", clusterName, logsPath)
if err != nil {
log.WithFields(log.Fields{
"cluster": clusterName,
"path": logsPath,
}).Warn("Failed to export Kind cluster logs")
} else {
log.WithFields(log.Fields{
"cluster": clusterName,
"path": logsPath,
}).Info("Kind cluster logs exported")
}
if !common.DeveloperMode {
cluster.Cleanup(suiteContext)
}
cancel()
})
}
func InitializeScenario(ctx *godog.ScenarioContext) {
scenarioCtx, cancel := context.WithCancel(context.Background())
log.DeferExitHandler(cancel)
var kubectl kubernetes.Control
var pods podsManager
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
tx = apme2e.StartTransaction(sc.Name, "test.scenario")
tx.Context.SetLabel("suite", "k8s Autodiscover")
kubectl = cluster.Kubectl().WithNamespace(scenarioCtx, "")
if kubectl.Namespace != "" {
log.Debugf("Running scenario %s in namespace: %s", sc.Name, kubectl.Namespace)
}
pods.kubectl = kubectl
pods.ctx = scenarioCtx
log.DeferExitHandler(func() { kubectl.Cleanup(scenarioCtx) })
return ctx, nil
})
ctx.After(func(ctx context.Context, sc *godog.Scenario, err error) (context.Context, error) {
if err != nil {
e := apm.DefaultTracer().NewError(err)
e.Context.SetLabel("scenario", sc.Name)
e.Context.SetLabel("gherkin_type", "scenario")
e.Send()
}
f := func() {
tx.End()
apm.DefaultTracer().Flush(nil)
}
defer f()
kubectl.Cleanup(scenarioCtx)
cancel()
return ctx, nil
})
ctx.StepContext().Before(func(ctx context.Context, step *godog.Step) (context.Context, error) {
log.Tracef("Before step: %s", step.Text)
stepSpan = tx.StartSpan(step.Text, "test.scenario.step", nil)
pods.ctx = apm.ContextWithSpan(scenarioCtx, stepSpan)
return ctx, nil
})
ctx.StepContext().After(func(ctx context.Context, step *godog.Step, status godog.StepResultStatus, err error) (context.Context, error) {
if err != nil {
e := apm.DefaultTracer().NewError(err)
e.Context.SetLabel("step", step.Text)
e.Context.SetLabel("gherkin_type", "step")
e.Context.SetLabel("step_status", status.String())
e.Send()
}
if stepSpan != nil {
stepSpan.End()
}
log.Tracef("After step (%s): %s", status.String(), step.Text)
return ctx, nil
})
ctx.Step(`^"([^"]*)" have passed$`, func(d string) error { return waitDuration(scenarioCtx, d) })
ctx.Step(`^"([^"]*)" is ([a-z]*)$`, func(name, state string) error {
return pods.resourceIs(name, state)
})
ctx.Step(`^"([^"]*)" is ([a-z]*) with "([^"]*)"$`, func(name, state, option string) error {
return pods.resourceIs(name, state, option)
})
ctx.Step(`^"([^"]*)" is ([a-z]*) with "([^"]*)" and "([^"]*)"$`, func(name, state, option1, option2 string) error {
return pods.resourceIs(name, state, option1, option2)
})
ctx.Step(`^"([^"]*)" collects events with "([^"]*:[^"]*)"$`, pods.collectsEventsWith)
ctx.Step(`^"([^"]*)" does not collect events with "([^"]*)" during "([^"]*)"$`, pods.doesNotCollectEvents)
ctx.Step(`^an ephemeral container is started in "([^"]*)"$`, pods.startEphemeralContainerIn)
}
var opts = godog.Options{
Output: colors.Colored(os.Stdout),
Format: "progress", // can define default values
}
func init() {
godog.BindCommandLineFlags("godog.", &opts) // godog v0.11.0 (latest)
}
func TestMain(m *testing.M) {
flag.Parse()
opts.Paths = flag.Args()
status := godog.TestSuite{
Name: "k8s-autodiscover",
TestSuiteInitializer: InitializeTestSuite,
ScenarioInitializer: InitializeScenario,
Options: &opts,
}.Run()
// Optional: Run `testing` package's logic besides godog.
if st := m.Run(); st > status {
status = st
}
os.Exit(status)
}