-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathact_helpers_test.go
85 lines (79 loc) · 1.79 KB
/
act_helpers_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
package act
import (
"context"
"testing"
"time"
sdkAct "github.com/gatewayd-io/gatewayd-plugin-sdk/act"
"github.com/stretchr/testify/assert"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
)
func createWaitActEntities(async bool) (
string,
map[string]*sdkAct.Action,
map[string]*sdkAct.Signal,
map[string]*sdkAct.Policy,
) {
name := "waitSync"
if async {
name = "waitAsync"
}
actions := map[string]*sdkAct.Action{
name: {
Name: name,
Metadata: nil,
Sync: !async,
Terminal: false,
Run: func(_ map[string]any, _ ...sdkAct.Parameter) (any, error) {
time.Sleep(1 * time.Second)
return true, nil
},
},
}
signals := map[string]*sdkAct.Signal{
name: {
Name: name,
Metadata: map[string]any{
"log": true,
"level": "info",
"message": "test",
"async": async,
},
},
}
policy := map[string]*sdkAct.Policy{
name: sdkAct.MustNewPolicy(
name,
`true`,
map[string]any{"log": "enabled"},
),
}
return name, actions, signals, policy
}
func createTestRedis(t *testing.T) string {
t.Helper()
ctx := context.Background()
req := testcontainers.ContainerRequest{
Image: "redis:6",
ExposedPorts: []string{"6379/tcp"},
WaitingFor: wait.ForAll(
wait.ForLog("Ready to accept connections"),
wait.ForListeningPort("6379/tcp"),
),
}
redisContainer, err := testcontainers.GenericContainer(
ctx, testcontainers.GenericContainerRequest{
ContainerRequest: req,
Started: true,
},
)
assert.NoError(t, err)
t.Cleanup(func() {
assert.NoError(t, redisContainer.Terminate(ctx))
})
host, err := redisContainer.Host(ctx)
assert.NoError(t, err)
port, err := redisContainer.MappedPort(ctx, "6379/tcp")
assert.NoError(t, err)
return host + ":" + port.Port()
}