forked from meshery/meshsync
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_test.go
More file actions
69 lines (58 loc) · 1.67 KB
/
Copy pathmain_test.go
File metadata and controls
69 lines (58 loc) · 1.67 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
package main
import (
"os"
"testing"
"time"
"github.com/layer5io/meshkit/broker"
"github.com/layer5io/meshkit/broker/nats"
"github.com/stretchr/testify/assert"
)
var runIntegrationTest bool
var testMeshsyncTopic = "meshery.meshsync.core"
var testMeshsyncNatsURL = "localhost:4222"
func init() {
runIntegrationTest = os.Getenv("RUN_INTEGRATION_TESTS") == "true"
}
/**
* this test requires k8s cluster (with installed CRDs: meshsync) and nats streaming
* --
* use docker compose to start nats
* ---
* TODO:
* - (maybe) add starting kind cluster to docker compose (this is not necessary anymore, as kind cluster is created in co workflow step, could be useful only for local run);
* - (maybe) run all test in container to avoid port exposure to host (this also could be useful only for local run to avoid port collision with host machine)
*/
func TestWithNatsIntegration(t *testing.T) {
if !runIntegrationTest {
t.Skip("skipping integration test")
}
br, err := nats.New(nats.Options{
URLS: []string{testMeshsyncNatsURL},
ConnectionName: "meshsync",
Username: "",
Password: "",
ReconnectWait: 2 * time.Second,
MaxReconnect: 60,
})
if err != nil {
t.Fatal("error connecting to nats", err)
}
count := 0
out := make(chan *broker.Message)
err = br.SubscribeWithChannel(testMeshsyncTopic, "", out)
if err != nil {
t.Fatalf("error subscribing to topic: %v", err)
}
go func() {
for range out {
count++
}
}()
os.Setenv("BROKER_URL", testMeshsyncNatsURL)
go main()
<-time.After(time.Second * 8)
// TODO some more meaningful check
assert.True(t, count > 0)
t.Logf("received %d messages from broker", count)
t.Log("done")
}