This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 579
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds binding.Bindable interface (#1613)
- Loading branch information
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package binding | ||
|
||
import "net/http" | ||
|
||
// Bindable when implemented, on a type | ||
// will override any Binders that have been | ||
// configured when using buffalo#Context.Bind | ||
type Bindable interface { | ||
Bind(*http.Request) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package binding | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type orbison struct { | ||
bound bool | ||
} | ||
|
||
func (o *orbison) Bind(req *http.Request) error { | ||
o.bound = true | ||
return nil | ||
} | ||
|
||
func Test_Bindable(t *testing.T) { | ||
r := require.New(t) | ||
|
||
req := httptest.NewRequest("GET", "/", nil) | ||
o := &orbison{} | ||
r.False(o.bound) | ||
r.NoError(Exec(req, o)) | ||
r.True(o.bound) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters