@@ -2,18 +2,22 @@ package main
2
2
3
3
import (
4
4
"context"
5
+ "io/ioutil"
5
6
"testing"
7
+ c "testsuites/collector"
6
8
7
9
"github.com/stretchr/testify/assert"
10
+ y "gopkg.in/yaml.v2"
8
11
)
9
12
10
- func TestExtractPublicMethodsFromFile (t * testing.T ) {
11
- fnsAnn , err := extractPublicMethodsFromFile (context .Background (), "./mocks/event.go" )
13
+ func TestCrawlSingleFileForFunctions (t * testing.T ) {
14
+ ctx := context .Background ()
15
+ fnsAnn , err := crawlSingleFileForFunctions (ctx , "./mocks/event.go" )
12
16
if err != nil {
13
17
t .Errorf ("got error: %v" , err .Error ())
14
18
}
15
19
16
- if len (fnsAnn ) != 2 {
20
+ if len (fnsAnn ) != 4 {
17
21
t .Errorf ("got %q, expected %q methods" , len (fnsAnn ), 2 )
18
22
}
19
23
@@ -24,4 +28,52 @@ func TestExtractPublicMethodsFromFile(t *testing.T) {
24
28
assert .Equal (t , "HelloEventWithParameter" , fnsAnn [1 ].Name )
25
29
assert .Equal (t , "(param string)" , fnsAnn [1 ].InputParams )
26
30
assert .Equal (t , "(string, error)" , fnsAnn [1 ].ReturnValues )
31
+
32
+ assert .Equal (t , "FunctionWithoutParameters" , fnsAnn [2 ].Name )
33
+ assert .Equal (t , "()" , fnsAnn [2 ].InputParams )
34
+ assert .Equal (t , "" , fnsAnn [2 ].ReturnValues )
35
+
36
+ assert .Equal (t , "FunctionWithPointerReturnValue" , fnsAnn [3 ].Name )
37
+ assert .Equal (t , "()" , fnsAnn [3 ].InputParams )
38
+ assert .Equal (t , "*Event" , fnsAnn [3 ].ReturnValues )
39
+ }
40
+
41
+ func TestMakeYAML (t * testing.T ) {
42
+
43
+ yaml := []c.FunctionAnnotation {
44
+ {
45
+ ID : 1 ,
46
+ Name : "SomeName" ,
47
+ InputParams : "(ctx context.Context, param Parameters)" ,
48
+ ReturnValues : "error" ,
49
+ Description : "" ,
50
+ Public : true ,
51
+ },
52
+ {
53
+ ID : 2 ,
54
+ Name : "SomeName2" ,
55
+ InputParams : "(ctx context.Context, param2 Parameters2)" ,
56
+ ReturnValues : "error" ,
57
+ Description : "" ,
58
+ Public : true ,
59
+ },
60
+ }
61
+
62
+ yamlData , err := y .Marshal (& yaml )
63
+ if err != nil {
64
+ t .Errorf ("got error: %v" , err .Error ())
65
+ }
66
+ fileName := "test.yaml"
67
+ err = ioutil .WriteFile (fileName , yamlData , 0644 )
68
+ if err != nil {
69
+ panic ("Unable to write data into the file" )
70
+ }
71
+
72
+ bytes , err := ioutil .ReadFile (fileName )
73
+ if err != nil {
74
+ t .Errorf ("got error: %v" , err .Error ())
75
+ }
76
+
77
+ assert .Equal (t , yamlData , bytes )
78
+
27
79
}
0 commit comments