Skip to content

Commit 279c8aa

Browse files
committed
Add test for make yaml and simplefy getting id
1 parent 1d44dd3 commit 279c8aa

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

test-crawler/main.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,8 @@ func makeYAML(ctx context.Context, filePath string) error {
114114
os.Exit(1)
115115
}
116116

117-
for i, fn := range publicMethods {
118-
i++
119-
fn.ID = i
120-
publicMethods = append(publicMethods[1:], fn)
117+
for i := 0; i < len(publicMethods); i++ {
118+
publicMethods[i].ID = i
121119
}
122120

123121
yamlData, err := y.Marshal(&publicMethods)

test-crawler/make_yaml_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
c "testsuites/collector"
6+
7+
y "gopkg.in/yaml.v2"
8+
9+
"github.com/stretchr/testify/assert"
10+
11+
"io/ioutil"
12+
)
13+
14+
func TestMakeYAML(t *testing.T) {
15+
16+
yaml := []c.FunctionAnnotation{
17+
{
18+
ID: 1,
19+
Name: "SomeName",
20+
InputParams: "(ctx context.Context, param Parameters)",
21+
ReturnValues: "error",
22+
Description: "",
23+
Public: true,
24+
},
25+
{
26+
ID: 2,
27+
Name: "SomeName2",
28+
InputParams: "(ctx context.Context, param2 Parameters2)",
29+
ReturnValues: "error",
30+
Description: "",
31+
Public: true,
32+
},
33+
}
34+
35+
yamlData, err := y.Marshal(&yaml)
36+
if err != nil {
37+
t.Errorf("got error: %v", err.Error())
38+
}
39+
fileName := "test.yaml"
40+
err = ioutil.WriteFile(fileName, yamlData, 0644)
41+
if err != nil {
42+
panic("Unable to write data into the file")
43+
}
44+
45+
bytes, err := ioutil.ReadFile(fileName)
46+
if err != nil {
47+
t.Errorf("got error: %v", err.Error())
48+
}
49+
50+
assert.Equal(t, yamlData, bytes)
51+
52+
}

0 commit comments

Comments
 (0)