-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpackage_test.go
More file actions
83 lines (71 loc) · 2.16 KB
/
Copy pathpackage_test.go
File metadata and controls
83 lines (71 loc) · 2.16 KB
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
// (c) Siemens AG 2023
//
// SPDX-License-Identifier: MIT
package ieddata
import (
"context"
"fmt"
"io"
"os"
"path"
"testing"
"time"
"github.com/thediveo/morbyd/v2"
"github.com/thediveo/morbyd/v2/build"
"github.com/thediveo/morbyd/v2/exec"
"github.com/thediveo/morbyd/v2/run"
"github.com/thediveo/morbyd/v2/session"
"golang.org/x/sys/unix"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/thediveo/success"
)
var sess *morbyd.Session
var fakecore *morbyd.Container
var _ = BeforeSuite(func(ctx context.Context) {
if os.Getuid() != 0 {
return
}
sess = Successful(morbyd.NewSession(ctx,
session.WithAutoCleaning("test.ieddata=")))
DeferCleanup(func(ctx context.Context) {
sess.Close(ctx)
sess = nil
})
By("building a fake edge core image if necessary")
const imgref = "ieddata/fake-core"
Expect(sess.BuildImage(ctx,
"tests/sqlite-alpine-appengine-db",
build.WithTag(imgref),
build.WithBuildArg("APPENGDBPATH="+dbBaseDir),
build.WithBuildArg("PLATFORMBOXDBNAME="+PlatformBoxDb),
)).Error().NotTo(HaveOccurred(), "image build failed")
By(fmt.Sprintf("deploying a fake edge core image %q", imgref))
fakecore = Successful(sess.Run(ctx,
imgref, run.WithName(EdgeIotCoreContainerName)))
DeferCleanup(func(ctx context.Context) {
fakecore.Kill(ctx)
})
Expect(fmt.Sprintf("/proc/%d/root/%s/%s",
Successful(fakecore.PID(ctx)), dbBaseDir, PlatformBoxDb)).To(BeAnExistingFile())
piper, pipew := io.Pipe()
cmdsess := Successful(fakecore.Exec(ctx,
exec.Command("sqlite3", path.Join(dbBaseDir, PlatformBoxDb)),
exec.WithCombinedOutput(GinkgoWriter),
exec.WithTTY(),
exec.WithInput(piper)))
DeferCleanup(func(ctx context.Context) {
_ = pipew.Close()
_ = piper.Close()
_ = unix.Kill(Successful(cmdsess.PID(ctx)), unix.SIGINT)
})
Expect(fmt.Fprint(pipew, "PRAGMA journal_mode=WAL;\n")).Error().To(Succeed())
Eventually(func() string {
return fmt.Sprintf("/proc/%d/root/%s/%s", Successful(fakecore.PID(ctx)), dbBaseDir, PlatformBoxDb+"-wal")
}).
Within(5 * time.Second).ProbeEvery(100 * time.Millisecond).To(BeAnExistingFile())
})
func TestIEDData(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "ieddata package")
}