Skip to content

Commit 5b8edaf

Browse files
committed
Generate basic YAML file
1 parent 7cb1556 commit 5b8edaf

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

test-crawler/collector/collector.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Function struct {
2929
}
3030

3131
type FunctionAnnotation struct {
32+
ID int `yaml:"id"`
3233
Name string `yaml:"name"`
3334
InputParams string `yaml:"inputParams"`
3435
ReturnValues string `yaml:"returnValues"`

test-crawler/main.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"encoding/json"
77
"fmt"
8+
"io/ioutil"
89
"os"
910
"os/exec"
1011
"strings"
@@ -13,6 +14,8 @@ import (
1314
a "testsuites/annotations"
1415
c "testsuites/collector"
1516
ex "testsuites/extractor"
17+
18+
y "gopkg.in/yaml.v2"
1619
)
1720

1821
type FnLink struct {
@@ -87,7 +90,8 @@ func crawlSingleFileForMethods(path string) {
8790
}
8891
for _, fn := range fns {
8992
fmt.Printf(
90-
"name %s : public %v : params: %s : return values : %s\n",
93+
"ID %d : name %s : public %v : params: %s : return values : %s\n",
94+
fn.ID,
9195
fn.Name,
9296
fn.Public,
9397
fn.InputParams,
@@ -100,6 +104,36 @@ func extractPublicMethodsFromFile(ctx context.Context, filePath string) ([]c.Fun
100104
return ex.GetExportedFunctions(ctx, filePath)
101105
}
102106

107+
// makeYAML will make yaml file from public methods.
108+
func makeYAML(ctx context.Context, filePath string) ([]byte, error) {
109+
110+
publicMethods, err := extractPublicMethodsFromFile(ctx, filePath)
111+
if err != nil {
112+
fmt.Print(err)
113+
os.Exit(1)
114+
}
115+
116+
var count int
117+
for _, fn := range publicMethods {
118+
count++
119+
fn.ID = count
120+
publicMethods = append(publicMethods[1:], fn)
121+
122+
}
123+
124+
yamlData, err := y.Marshal(&publicMethods)
125+
if err != nil {
126+
fmt.Printf("Error while Marshaling. %v", err)
127+
}
128+
129+
fileName := "test.yaml"
130+
err = ioutil.WriteFile(fileName, yamlData, 0644)
131+
if err != nil {
132+
panic("Unable to write data into the file")
133+
}
134+
return yamlData, nil
135+
}
136+
103137
func linkFiles(flist []c.Function) (links [][]FnLink) {
104138

105139
functions := make(map[string]c.Function)

0 commit comments

Comments
 (0)