Added template sorter, MainTest separation

* Moved MainTests into a dedicated folder
* Added sorter for templates (sorts structs to top)
* Fixed all the broken tests
* Tidied up output.go functions
* Only creating one MainTest (main_test.go) per app run now
* Split test imports up into normal test imports & main test imports
This commit is contained in:
Patrick O'brien 2016-04-07 06:10:12 +10:00
commit d3aeb7375d
13 changed files with 399 additions and 198 deletions

View file

@ -34,9 +34,23 @@ func init() {
},
},
},
PkgName: "patrick",
OutFolder: "",
Interface: nil,
PkgName: "patrick",
OutFolder: "",
DriverName: "postgres",
Interface: nil,
}
}
func TestLoadTemplate(t *testing.T) {
t.Parallel()
template, err := loadTemplate("templates_test/main_test", "postgres_main.tpl")
if err != nil {
t.Fatalf("Unable to loadTemplate: %s", err)
}
if template == nil {
t.Fatal("Unable to load template.")
}
}
@ -65,6 +79,11 @@ func TestTemplates(t *testing.T) {
t.Errorf("Templates is empty.")
}
cmdData.TestMainTemplate, err = loadTemplate("templates_test/main_test", "postgres_main.tpl")
if err != nil {
t.Fatalf("Unable to initialize templates: %s", err)
}
cmdData.OutFolder, err = ioutil.TempDir("", "templates")
if err != nil {
t.Fatalf("Unable to create tempdir: %s", err)
@ -78,7 +97,7 @@ func TestTemplates(t *testing.T) {
buf := bytes.Buffer{}
buf2 := bytes.Buffer{}
cmd := exec.Command("go", "test")
cmd := exec.Command("go", "test", "-c")
cmd.Dir = cmdData.OutFolder
cmd.Stderr = &buf
cmd.Stdout = &buf2