Skip to content
This repository has been archived by the owner on Apr 30, 2021. It is now read-only.

Commit

Permalink
Generate spec for each controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Svetlin Ralchev committed Dec 13, 2019
1 parent da96b67 commit 3e0f3ca
Show file tree
Hide file tree
Showing 5 changed files with 331 additions and 172 deletions.
11 changes: 11 additions & 0 deletions syntax/golang/dom.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ func (f *File) WriteTo(w io.Writer) (int64, error) {
return int64(n), err
}

// ReadFrom reads the content from a file
func (f *File) ReadFrom(r io.Reader) (int64, error) {
node, err := decorator.Parse(r)
if err != nil {
return 0, err
}

f.node = node
return 0, nil
}

// AddNode adds a node to the file
func (f *File) AddNode(node Node) {
f.node.Decls = append(f.node.Decls, node.Node())
Expand Down
35 changes: 33 additions & 2 deletions syntax/golang/generator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package golang
import (
"bytes"
"fmt"
"go/build"
"net/http"
"path/filepath"
"strings"
Expand Down Expand Up @@ -295,12 +296,42 @@ func (g *ControllerGenerator) controller(root *File) {
"summary": operation.Summary,
"deprecated": operation.DeprecationMessage(),
})

}
}

func (g *ControllerGenerator) spec(root *File) {
//TODO:
g.Reporter.Error("ﳑ Generating tests: %s...", root.Name())

project, err := filepath.Rel(filepath.Join(build.Default.GOPATH, "src"), g.Path)
if err != nil {
g.Reporter.Error(" Generating markdown documentation fail: ", err)
return
}

ctx := map[string]interface{}{
"receiver": inflect.Camelize(g.Controller.Name) + "API",
"project": project,
"operations": g.Controller.Operations,
}

writer := &syntax.TemplateWriter{
Path: "syntax/golang/spec.go.tpl",
Context: ctx,
}

buffer := &bytes.Buffer{}

if _, err := writer.WriteTo(buffer); err != nil {
g.Reporter.Error("ﳑ Generating tests: %s fail: %v", root.Name(), err)
return
}

if _, err := root.ReadFrom(buffer); err != nil {
g.Reporter.Error("ﳑ Generating tests: %s fail: %v", root.Name(), err)
return
}

g.Reporter.Success("ﳑ Generating tests: %s success", root.Name())
}

func (g *ControllerGenerator) function(root *File, name string, ctx map[string]interface{}) {
Expand Down
Loading

0 comments on commit 3e0f3ca

Please sign in to comment.