-
Notifications
You must be signed in to change notification settings - Fork 16
/
integration_test.go
85 lines (68 loc) · 1.68 KB
/
integration_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
// +build integration
package wormhole_test
import (
"io/ioutil"
"testing"
"time"
"github.com/alicebob/miniredis"
"github.com/sirupsen/logrus"
"github.com/superfly/wormhole"
"github.com/superfly/wormhole/config"
"github.com/gomodule/redigo/redis"
)
var fakeRedis *miniredis.Miniredis
var redisURL string
func testServerConfig(t *testing.T, redisURL string) *config.ServerConfig {
c, err := redis.Dial("tcp", redisURL)
if err != nil {
t.Fatal(err)
}
// make sure that token is registered in Redis for this backend ID
c.Do("HSET", "backend_tokens", "fly_token", "1")
sshKey, err := ioutil.ReadFile("testdata/id_rsa")
if err != nil {
t.Fatal(err)
}
sc := &config.ServerConfig{
RedisURL: "redis://" + redisURL,
SSHPrivateKey: sshKey,
}
logger := logrus.New()
sc.Logger = logger
sc.Port = "13579"
return sc
}
func testClientConfig(t *testing.T) *config.ClientConfig {
cc := &config.ClientConfig{
Token: "fly_token",
RemoteEndpoint: "127.0.0.1:13579",
}
logger := logrus.New()
cc.Logger = logger
return cc
}
func testServer(redisURL string, t *testing.T) {
wormhole.StartRemote(testServerConfig(t, redisURL))
}
func testClient(t *testing.T) {
wormhole.StartLocal(testClientConfig(t))
}
func TestClientConnect(t *testing.T) {
fakeRedis, err := miniredis.Run()
if err != nil {
t.Fatal(err)
}
redisURL := fakeRedis.Addr()
go testServer(redisURL, t)
go testClient(t)
// wait for SSH handshake
time.Sleep(1 * time.Second)
c, err := redis.Dial("tcp", redisURL)
if err != nil {
t.Fatal(err)
}
_, err = c.Do("SMEMBERS", "backend:1:sessions")
if err != nil {
t.Fatalf("Expected backend to have started a new session: %s", err.Error())
}
}