forked from semrush/zenrpc
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathserver_test.go
47 lines (38 loc) · 1.11 KB
/
server_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
package zenrpc_test
import (
"bytes"
"encoding/json"
"os"
"testing"
"github.com/vmkteam/zenrpc/v2"
"github.com/vmkteam/zenrpc/v2/testdata"
)
var rpc = zenrpc.NewServer(zenrpc.Options{BatchMaxLen: 5, AllowCORS: true})
func init() {
rpc.Register("arith", &testdata.ArithService{})
rpc.Register("", &testdata.ArithService{})
//rpc.Use(zenrpc.Logger(log.New(os.Stderr, "", log.LstdFlags)))
}
func TestServer_SMD(t *testing.T) {
r := rpc.SMD()
if b, err := json.Marshal(r); err != nil {
t.Fatal(err)
} else if !bytes.Contains(b, []byte("default")) {
t.Error(string(b))
}
}
func TestServer_SmdGenerate(t *testing.T) {
rpc := zenrpc.NewServer(zenrpc.Options{})
rpc.Register("phonebook", testdata.PhoneBook{DB: testdata.People})
rpc.Register("arith", testdata.ArithService{})
rpc.Register("printer", testdata.PrintService{})
rpc.Register("", testdata.ArithService{})
b, _ := json.MarshalIndent(rpc.SMD(), "", " ")
testData, err := os.ReadFile("./testdata/testdata/arithsrv-smd.json")
if err != nil {
t.Fatalf("open test data file")
}
if !bytes.Equal(b, testData) {
t.Fatalf("bad zenrpc output")
}
}