-
Notifications
You must be signed in to change notification settings - Fork 0
/
package_test.go
85 lines (75 loc) · 1.82 KB
/
package_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
// (c) Siemens AG 2023
//
// SPDX-License-Identifier: MIT
package ieddata
import (
"errors"
"os"
"testing"
"time"
"github.com/cenkalti/backoff/v4"
"github.com/ory/dockertest/v3"
"github.com/ory/dockertest/v3/docker"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var pool *dockertest.Pool
var fakecore *dockertest.Resource
func SetupSuite() {
var err error
pool, err = dockertest.NewPool("unix:///run/docker.sock")
if err != nil {
panic(err)
}
_ = pool.Client.RemoveContainer(docker.RemoveContainerOptions{
ID: EdgeIotCoreContainerName,
Force: true,
})
fakecore, err = pool.BuildAndRunWithBuildOptions(
&dockertest.BuildOptions{
Dockerfile: "Dockerfile",
ContextDir: "tests/sqlite-alpine-appengine-db",
BuildArgs: []docker.BuildArg{
{Name: "APPENGDBPATH", Value: dbBaseDir},
},
},
&dockertest.RunOptions{
Name: EdgeIotCoreContainerName,
})
if err != nil {
panic(err)
}
// wait for the container to be properly alive...
err = backoff.Retry(func() error {
c, err := pool.Client.InspectContainer(EdgeIotCoreContainerName)
if err != nil {
return err
}
if !c.State.Running {
return errors.New("edge core not running")
}
return nil
}, backoff.WithMaxRetries(backoff.NewConstantBackOff(250*time.Millisecond), 4*5))
if err != nil {
panic(err)
}
}
func TeardownSuite() {
if pool != nil && fakecore != nil {
_ = pool.Purge(fakecore)
}
}
func TestIEDData(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "ieddata package")
}
func TestMain(m *testing.M) {
// We need the fake edge core container to be present also for the testable
// examples and we need to properly clean up when a testable example fails,
// so we have to wrap everything to ensure running TeardownSuite.
os.Exit(func() int {
SetupSuite()
defer TeardownSuite()
return m.Run()
}())
}