Skip to content

Commit

Permalink
Added test to ensure values are still set on request
Browse files Browse the repository at this point in the history
  • Loading branch information
Danzabar committed Nov 6, 2015
1 parent 5d1a6fc commit 2026175
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package forms

import (
"github.com/stretchr/testify/assert"
"io/ioutil"
"net/http"
"strings"
"testing"
)

Expand All @@ -23,6 +25,31 @@ func TestBuildingForm(t *testing.T) {
assert.Equal(t, 4, len(b.Form.Fields))
}

// Test building a form with pre-defined values
func TestBuildPreValues(t *testing.T) {
r := http.Request{
Method: "POST",
Body: ioutil.NopCloser(strings.NewReader("test=foo&test2=bar&test3=test1")),
Header: http.Header{
"Content-Type": {"application/x-www-form-urlencoded"},
},
}

b := NewBuilder("example.yml", r)
b.build()

for _, field := range b.Form.Fields {
switch field.Name {
case "test":
assert.Equal(t, "foo", field.Value)
case "test2":
assert.Equal(t, "bar", field.Value)
case "test3":
assert.Equal(t, "test1", field.Value)
}
}
}

// Build benchmark
func BenchmarkBuildFormFromConfig(t *testing.B) {
b := NewBuilder("example.yml", request)
Expand Down

0 comments on commit 2026175

Please sign in to comment.