github.com/theliebeskind/genfig@v0.1.5-alpha/plugins/tester.go (about) 1 package plugins 2 3 import ( 4 "io" 5 "text/template" 6 7 "github.com/theliebeskind/genfig/models" 8 ) 9 10 type configTestPlugin struct { 11 tpl *template.Template 12 } 13 14 var ( 15 configTest = configTestPlugin{ 16 tpl: template.Must(template. 17 New("configTest"). 18 Parse(`import "testing" 19 20 func Test_CurrentConfig(t *testing.T) { 21 if Current == nil { 22 t.Error("Current config is nil") 23 } 24 } 25 `))} 26 ) 27 28 func init() { 29 // "register" plugin 30 Plugins["config_test"] = &configTest 31 } 32 33 // GetInitCall returns the availibility and the string of the 34 // function to be called on init 35 func (p *configTestPlugin) GetInitCall() (string, bool) { 36 return "", false 37 } 38 39 // SetSchemaMap sets the schema to be used when WriteTo is called 40 func (p *configTestPlugin) SetSchemaMap(_ models.SchemaMap) { 41 } 42 43 // WriteTo performs the acutal writing to a buffer (or io.Writer). 44 // For this plugin, the template is simply "rendered" into the writer. 45 func (p *configTestPlugin) WriteTo(w io.Writer) (l int64, err error) { 46 err = p.tpl.Execute(w, nil) 47 return 48 }