Skip to content
File

Blob: tun/server/resolve_test.go

go68 lines
1package server
2 
3import (
4 "testing"
5 "time"
6 
7 "go.miragespace.co/specter/spec/protocol"
8 "go.miragespace.co/specter/spec/tun"
9 
10 "github.com/stretchr/testify/mock"
11 "github.com/stretchr/testify/require"
12)
13 
14func TestIdentitiesRoutine(t *testing.T) {
15 as := require.New(t)
16 
17 _, node, clientT, chordT, serv := getFixture(t, as)
18 _, cht, tn := getIdentities()
19 
20 ctx := t.Context()
21 
22 chordT.On("Identity").Return(cht)
23 clientT.On("Identity").Return(tn)
24 
25 // On start up -> publish
26 node.On("Put", mock.Anything, mock.MatchedBy(func(k []byte) bool {
27 exp := [][]byte{
28 []byte(tun.DestinationByChordKey(cht)),
29 []byte(tun.DestinationByTunnelKey(tn)),
30 }
31 return assertBytes(k, exp...)
32 }), mock.MatchedBy(func(v []byte) bool {
33 pair := &protocol.TunnelDestination{}
34 err := pair.UnmarshalVT(v)
35 if err != nil {
36 return false
37 }
38 if pair.GetChord().GetId() != cht.GetId() {
39 return false
40 }
41 if pair.GetTunnel().GetId() != tn.GetId() {
42 return false
43 }
44 return true
45 })).Return(nil)
46 
47 // On stop -> unpublish
48 node.On("Delete", mock.Anything, mock.MatchedBy(func(k []byte) bool {
49 exp := [][]byte{
50 []byte(tun.DestinationByChordKey(cht)),
51 []byte(tun.DestinationByTunnelKey(tn)),
52 }
53 return assertBytes(k, exp...)
54 })).Return(nil)
55 
56 serv.MustRegister(ctx)
57 
58 <-time.After(time.Millisecond * 100)
59 
60 serv.Stop()
61 
62 <-time.After(time.Millisecond * 100)
63 
64 node.AssertExpectations(t)
65 clientT.AssertExpectations(t)
66 chordT.AssertExpectations(t)
67}