Skip to content

Commit

Permalink
test that the index doesn't blow up trivially
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhodges committed Nov 9, 2013
1 parent 40f683a commit f837d58
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
12 changes: 8 additions & 4 deletions howsmyssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ var (

func main() {
flag.Parse()
index = template.Must(template.New("index.html").
Funcs(template.FuncMap{"sentence": sentence}).
ParseFiles(*tmplDir + "/index.html"))

index = loadIndex()
_, httpsPort, err := net.SplitHostPort(*httpsAddr)
if err != nil {
log.Fatalf("unable to parse httpsAddr: %s", err)
Expand Down Expand Up @@ -226,6 +223,13 @@ func tlsRedirect(vhost, port string, webHandler http.Handler) http.Handler {
return h
}

func loadIndex() *template.Template {
return template.Must(template.New("index.html").
Funcs(template.FuncMap{"sentence": sentence}).
ParseFiles(*tmplDir + "/index.html"))

}

func sentence(parts []string) string {
if len(parts) == 1 {
return parts[0] + "."
Expand Down
18 changes: 18 additions & 0 deletions index_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"testing"
"bytes"
)

func TestDumbNilishIndex(t *testing.T) {
tmpl := loadIndex()
buf := new(bytes.Buffer)
err := tmpl.Execute(buf, &clientInfo{})
if err != nil {
t.Errorf("index execution blew up with nilish clientInfo: %#v", err)
}
if len(buf.Bytes()) == 0 {
t.Errorf("index execution did not write anything")
}
}

0 comments on commit f837d58

Please sign in to comment.