-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathprotocolserver_test.go
More file actions
42 lines (32 loc) · 873 Bytes
/
Copy pathprotocolserver_test.go
File metadata and controls
42 lines (32 loc) · 873 Bytes
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
package desync
import (
"context"
"io"
"testing"
"github.com/stretchr/testify/require"
)
func TestProtocolServer(t *testing.T) {
r1, w1 := io.Pipe()
r2, w2 := io.Pipe()
server := NewProtocol(r1, w2)
// Test data
uncompressed := []byte{4, 3, 2, 1}
chunkIn := NewChunk(uncompressed)
id := chunkIn.ID()
store := &TestStore{}
store.StoreChunk(chunkIn)
ps := NewProtocolServer(r2, w1, store)
go ps.Serve(context.Background())
// Client
flags, err := server.Initialize(CaProtocolPullChunks)
require.NoError(t, err)
require.NotZero(t, flags&CaProtocolReadableStore, "server not offering chunks")
// Should find this chunk
chunk, err := server.RequestChunk(id)
require.NoError(t, err)
b, _ := chunk.Data()
require.Equal(t, uncompressed, b)
// This one's missing
_, err = server.RequestChunk(ChunkID{0})
require.IsType(t, ChunkMissing{}, err)
}