Update generator

This commit is contained in:
Adrian Zankich 2014-06-13 15:09:04 -07:00
parent 56848d5a81
commit a1f0bd2842
1 changed files with 28 additions and 62 deletions

View File

@ -100,17 +100,6 @@ func Generate() cli.Command {
} }
adaptorTest.Execute(f, name) adaptorTest.Execute(f, name)
f.Close() f.Close()
testSuite, _ := template.New("").Parse(testSuite())
fileLocation = fmt.Sprintf("%s/%s_suite_test.go", dir, args[0])
fmt.Println("Creating", fileLocation)
f, err = os.Create(fileLocation)
if err != nil {
fmt.Println(err)
err = nil
}
testSuite.Execute(f, name)
f.Close()
}, },
} }
} }
@ -163,8 +152,8 @@ func New{{.UpperName}}Driver(a *{{.UpperName}}Adaptor, name string) *{{.UpperNam
return &{{.UpperName}}Driver{ return &{{.UpperName}}Driver{
Driver: gobot.Driver{ Driver: gobot.Driver{
Name: name, Name: name,
Events: make(map[string]chan interface{}), Events: make(map[string]*gobot.Event),
Commands: []string{}, Commands: make(map[string]func(map[string]interface{}) interface{}),
}, },
Adaptor: a, Adaptor: a,
} }
@ -179,26 +168,23 @@ func driverTest() string {
return `package {{ .Name }} return `package {{ .Name }}
import ( import (
. "github.com/onsi/ginkgo" "github.com/hybridgroup/gobot"
. "github.com/onsi/gomega" "testing"
) )
var _ = Describe("{{ .UpperName }}Driver", func() { func initTest{{ .UpperName }}Driver() *{{ .UpperName }}Driver {
var ( return New{{ .UpperName}}Driver(New{{ .UpperName }}Adaptor("myAdaptor"), "myDriver")
driver *{{ .UpperName }}Driver }
)
BeforeEach(func() { func Test{{ .UpperName }}DriverStart(t *testing.T) {
driver = New{{ .UpperName }}Driver(New{{ .UpperName }}Adaptor("adaptor"), "driver") d := initTest{{.UpperName }}Driver()
}) gobot.Expect(t, d.Start(), true)
}
It("Must be able to Start", func() { func Test{{ .UpperName }}DriverHalt(t *testing.T) {
Expect(driver.Start()).To(Equal(true)) d := initTest{{.UpperName }}Driver()
}) gobot.Expect(t, d.Halt(), true)
It("Must be able to Halt", func() { }
Expect(driver.Halt()).To(Equal(true))
})
})
` `
} }
@ -206,42 +192,22 @@ func adaptorTest() string {
return `package {{ .Name }} return `package {{ .Name }}
import ( import (
. "github.com/onsi/ginkgo" "github.com/hybridgroup/gobot"
. "github.com/onsi/gomega"
)
var _ = Describe("{{ .UpperName }}Adaptor", func() {
var (
adaptor *{{ .UpperName }}Adaptor
)
BeforeEach(func() {
adaptor = New{{ .UpperName }}Adaptor("adaptor")
})
It("Must be able to Finalize", func() {
Expect(adaptor.Finalize()).To(Equal(true))
})
It("Must be able to Connect", func() {
Expect(adaptor.Connect()).To(Equal(true))
})
})
`
}
func testSuite() string {
return `package {{ .Name }}
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing" "testing"
) )
func TestGobot{{ .UpperName }}(t *testing.T) { func initTest{{ .UpperName }}Adaptor() *{{ .UpperName }}Adaptor {
RegisterFailHandler(Fail) return New{{ .UpperName }}Adaptor("myAdaptor")
RunSpecs(t, "{{ .UpperName }} Suite") }
func Test{{ .UpperName }}AdaptorConnect(t *testing.T) {
a := initTest{{.UpperName }}Adaptor()
gobot.Expect(t, a.Connect(), true)
}
func Test{{ .UpperName }}AdaptorFinalize(t *testing.T) {
a := initTest{{.UpperName }}Adaptor()
gobot.Expect(t, a.Finalize(), true)
} }
` `
} }