forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththrift_idl_test.go
More file actions
53 lines (43 loc) · 1.02 KB
/
thrift_idl_test.go
File metadata and controls
53 lines (43 loc) · 1.02 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
package main
import (
"io/ioutil"
"os"
"testing"
)
func thriftIdlForTesting(t *testing.T, content string) *ThriftIdl {
f, _ := ioutil.TempFile("", "")
defer os.Remove(f.Name())
f.WriteString(content)
f.Close()
idl, err := NewThriftIdl([]string{f.Name()})
if err != nil {
t.Fatal("Parsing failed:", err)
}
return idl
}
func TestThriftIdl_thriftReadFiles(t *testing.T) {
if testing.Verbose() {
LogInit(LOG_DEBUG, "", false, []string{"thrift", "thriftdetailed"})
}
idl := thriftIdlForTesting(t, `
/* simple test */
service Test {
i32 add(1:i32 num1, 2: i32 num2)
}
`)
methods_map := idl.MethodsByName
if len(methods_map) == 0 {
t.Error("Empty methods_map")
}
m, exists := methods_map["add"]
if !exists || m.Service == nil || m.Method == nil ||
m.Service.Name != "Test" || m.Method.Name != "add" {
t.Error("Bad data:", m)
}
if *m.Params[1] != "num1" || *m.Params[2] != "num2" {
t.Error("Bad params", m.Params)
}
if len(m.Exceptions) != 0 {
t.Error("Non empty exceptions", m.Exceptions)
}
}