-
Notifications
You must be signed in to change notification settings - Fork 53
/
endpoint_test.go
44 lines (36 loc) · 1.03 KB
/
endpoint_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
package weaver
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewEndpoint(t *testing.T) {
endpointConfig := &EndpointConfig{
Matcher: "path",
ShardExpr: "/.*",
ShardFunc: "lookup",
ShardConfig: json.RawMessage(`{}`),
}
sharder := &stubSharder{}
endpoint, err := NewEndpoint(endpointConfig, sharder)
require.NoError(t, err, "should not fail to create an endpoint from endpointConfig")
assert.NotNil(t, endpoint, "should create an endpoint")
assert.Equal(t, sharder, endpoint.sharder)
}
func TestNewEndpoint_SharderIsNil(t *testing.T) {
endpointConfig := &EndpointConfig{
Matcher: "path",
ShardExpr: "/.*",
ShardFunc: "lookup",
ShardConfig: json.RawMessage(`{}`),
}
endpoint, err := NewEndpoint(endpointConfig, nil)
assert.Error(t, err, "should fail to create an endpoint when sharder is nil")
assert.Nil(t, endpoint)
}
type stubSharder struct {
}
func (stub *stubSharder) Shard(key string) (*Backend, error) {
return nil, nil
}