-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathserver_delegated_routing_test.go
More file actions
116 lines (89 loc) · 3.43 KB
/
server_delegated_routing_test.go
File metadata and controls
116 lines (89 loc) · 3.43 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCollectEndpoints(t *testing.T) {
t.Run("deduplicates same URL across multiple endpoint types", func(t *testing.T) {
cfg := &config{
contentEndpoints: []string{"https://example.com"},
peerEndpoints: []string{"https://example.com"},
ipnsEndpoints: []string{"https://example.com"},
}
endpoints := collectEndpoints(cfg)
require.Len(t, endpoints, 1, "should have exactly one endpoint")
assert.Equal(t, "https://example.com", endpoints[0].baseURL)
assert.True(t, endpoints[0].providers, "should support providers")
assert.True(t, endpoints[0].peers, "should support peers")
assert.True(t, endpoints[0].ipns, "should support ipns")
})
t.Run("handles different URLs separately", func(t *testing.T) {
cfg := &config{
contentEndpoints: []string{"https://a.com", "https://b.com"},
peerEndpoints: []string{"https://b.com", "https://c.com"},
}
endpoints := collectEndpoints(cfg)
require.Len(t, endpoints, 3, "should have three separate endpoints")
// Convert to map for easier testing
urlMap := make(map[string]endpointConfig)
for _, ep := range endpoints {
urlMap[ep.baseURL] = ep
}
// Verify a.com (providers only)
assert.True(t, urlMap["https://a.com"].providers)
assert.False(t, urlMap["https://a.com"].peers)
assert.False(t, urlMap["https://a.com"].ipns)
// Verify b.com (providers and peers)
assert.True(t, urlMap["https://b.com"].providers)
assert.True(t, urlMap["https://b.com"].peers)
assert.False(t, urlMap["https://b.com"].ipns)
// Verify c.com (peers only)
assert.False(t, urlMap["https://c.com"].providers)
assert.True(t, urlMap["https://c.com"].peers)
assert.False(t, urlMap["https://c.com"].ipns)
})
t.Run("skips empty strings", func(t *testing.T) {
cfg := &config{
contentEndpoints: []string{"https://example.com", "", "https://another.com"},
peerEndpoints: []string{""},
}
endpoints := collectEndpoints(cfg)
require.Len(t, endpoints, 2, "should skip empty strings")
urlMap := make(map[string]endpointConfig)
for _, ep := range endpoints {
urlMap[ep.baseURL] = ep
}
assert.Contains(t, urlMap, "https://example.com")
assert.Contains(t, urlMap, "https://another.com")
assert.NotContains(t, urlMap, "")
})
t.Run("handles all three endpoint types for different URLs", func(t *testing.T) {
cfg := &config{
contentEndpoints: []string{"https://provider.com"},
peerEndpoints: []string{"https://peer.com"},
ipnsEndpoints: []string{"https://ipns.com"},
}
endpoints := collectEndpoints(cfg)
require.Len(t, endpoints, 3)
urlMap := make(map[string]endpointConfig)
for _, ep := range endpoints {
urlMap[ep.baseURL] = ep
}
// Each URL should have only one capability enabled
assert.True(t, urlMap["https://provider.com"].providers)
assert.False(t, urlMap["https://provider.com"].peers)
assert.False(t, urlMap["https://provider.com"].ipns)
assert.False(t, urlMap["https://peer.com"].providers)
assert.True(t, urlMap["https://peer.com"].peers)
assert.False(t, urlMap["https://peer.com"].ipns)
assert.False(t, urlMap["https://ipns.com"].providers)
assert.False(t, urlMap["https://ipns.com"].peers)
assert.True(t, urlMap["https://ipns.com"].ipns)
})
t.Run("empty config returns empty list", func(t *testing.T) {
cfg := &config{}
endpoints := collectEndpoints(cfg)
assert.Empty(t, endpoints)
})
}