Skip to content

Commit

Permalink
Remove reflection from TestKeys
Browse files Browse the repository at this point in the history
Now using an actual template. Most tests should probably do this.
  • Loading branch information
md5 committed Feb 26, 2015
1 parent ef19866 commit ad7451f
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions template_test.go
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"reflect"
"testing"
"text/template"
)

func TestContains(t *testing.T) {
Expand All @@ -27,20 +28,16 @@ func TestKeys(t *testing.T) {
expected: "demo.local",
}

k, err := keys(env)
if err != nil {
t.Fatalf("Error fetching keys: %v", err)
}
vk := reflect.ValueOf(k)
if vk.Kind() == reflect.Invalid {
t.Fatalf("Got invalid kind for keys: %v", vk)
}
const text = "{{range (keys $)}}{{.}}{{end}}"
tmpl := template.Must(newTemplate("keys-test").Parse(text))

if len(env) != vk.Len() {
t.Fatalf("Incorrect key count; expected %s, got %s", len(env), vk.Len())
var b bytes.Buffer
err := tmpl.ExecuteTemplate(&b, "keys-test", env)
if err != nil {
t.Fatalf("Error executing template: %v", err)
}

got := vk.Index(0).Interface()
got := b.String()
if expected != got {
t.Fatalf("Incorrect key found; expected %s, got %s", expected, got)
}
Expand Down

0 comments on commit ad7451f

Please sign in to comment.