-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathquorum_test.go
103 lines (90 loc) · 3 KB
/
quorum_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package bootstrap_test
import (
"context"
"errors"
"net"
"time"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/james-lawrence/bw"
"github.com/james-lawrence/bw/agent"
"github.com/james-lawrence/bw/agenttestutil"
"github.com/james-lawrence/bw/agentutil"
. "github.com/james-lawrence/bw/bootstrap"
"github.com/james-lawrence/bw/cluster"
"github.com/james-lawrence/bw/clustering"
"github.com/james-lawrence/bw/internal/testingx"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
var _ = Describe("Quorum", func() {
var (
peer1 = agent.NewPeer("node1")
archive1 = agent.Archive{
Peer: peer1,
Ts: time.Now().Unix(),
DeploymentID: bw.MustGenerateID(),
}
dopts1 = agent.DeployOptions{
Timeout: int64(time.Hour),
SilenceDeployLogs: true,
}
)
It("should succeed when no errors occur", func() {
c := agent.Config{
Root: testingx.TempDir(),
}
p := agent.NewPeer("local")
d, srv := testingx.NewGRPCServer2(func(srv *grpc.Server) {
(&agenttestutil.FakeQuorum{
InfoResponse: agent.InfoResponse{
Mode: agent.InfoResponse_None,
Deployed: &agent.DeployCommand{
Command: agent.DeployCommand_Done,
Archive: &archive1,
Options: &dopts1,
},
},
}).Bind(srv)
})
defer testingx.GRPCCleanup(nil, srv)
mc := cluster.New(p, clustering.NewSingleNode("node1", net.ParseIP("127.0.0.1")))
Expect(Run(context.Background(), SocketQuorum(c), NewQuorum(mc, d))).To(Succeed())
_, err := Latest(context.Background(), SocketQuorum(c), grpc.WithTransportCredentials(insecure.NewCredentials()))
Expect(err).To(Succeed())
})
It("should return no deployments error when no deployments exist", func() {
c := agent.Config{
Root: testingx.TempDir(),
}
p := agent.NewPeer("local")
d, srv := testingx.NewGRPCServer2(func(srv *grpc.Server) {
(&agenttestutil.FakeQuorum{
InfoResponse: agent.InfoResponse{
Mode: agent.InfoResponse_None,
},
}).Bind(srv)
})
defer testingx.GRPCCleanup(nil, srv)
mc := cluster.New(p, clustering.NewSingleNode("node1", net.ParseIP("127.0.0.1")))
Expect(Run(context.Background(), SocketQuorum(c), NewQuorum(mc, d))).To(Succeed())
_, err := Latest(context.Background(), SocketQuorum(c), grpc.WithTransportCredentials(insecure.NewCredentials()))
Expect(err).To(Equal(agentutil.ErrNoDeployments))
})
It("should error out when an error occurrs", func() {
c := agent.Config{
Root: testingx.TempDir(),
}
p := agent.NewPeer("local")
d, srv := testingx.NewGRPCServer2(func(srv *grpc.Server) {
(&agenttestutil.FakeQuorum{
ErrResult: errors.New("boom"),
}).Bind(srv)
})
defer testingx.GRPCCleanup(nil, srv)
mc := cluster.New(p, clustering.NewSingleNode("node1", net.ParseIP("127.0.0.1")))
Expect(Run(context.Background(), SocketQuorum(c), NewQuorum(mc, d))).To(Succeed())
_, err := Latest(context.Background(), SocketQuorum(c), grpc.WithTransportCredentials(insecure.NewCredentials()))
Expect(err).To(HaveOccurred())
})
})