-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2b4db9
commit e7ba595
Showing
7 changed files
with
317 additions
and
67 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
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
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,16 @@ | ||
package gomek | ||
|
||
import "testing" | ||
|
||
func TestTemplate_Run(t *testing.T) { | ||
template := Template{base: []string{"base.html"}} | ||
routeTemplates := []string{"/index.gohtml", "/news.gohtml"} | ||
result := template.Run(routeTemplates...) | ||
expected := []string{"base.html", "/index.gohtml", "/news.gohtml"} | ||
for i, _ := range result { | ||
if result[i] != expected[i] { | ||
t.Errorf("expected %v got %v", result[i], expected[i]) | ||
} | ||
} | ||
|
||
} |
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 @@ | ||
package gomek |
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,35 @@ | ||
package gomek | ||
|
||
import "net/http" | ||
|
||
// CreateTestHandler this function provides an easy way to access the | ||
// `http.HandlerFunc` func. Testing gomek views is thus the same as testing | ||
// any regular HandlerFunc handlers. | ||
// | ||
// c := Config{} | ||
// mockApp := NewTestApp(c) | ||
// mockApp.Route("/blogs").Methods("POST").Resource(&Notice{}) | ||
// mockApp.Start() | ||
// | ||
// notice := Notice{} | ||
// | ||
// handler := CreateTestHandler(mockApp, notice.Post) | ||
// | ||
// req := httptest.NewRequest(http.MethodPost, "/blogs", nil) | ||
// w := httptest.NewRecorder() | ||
// handler(w, req) // regular HandlerFunc | ||
// resp := w.Result() | ||
// | ||
// defer resp.Body.Close() | ||
// data, err := io.ReadAll(resp.Body) | ||
// if err != nil { | ||
// t.Errorf("Error: %v", err) | ||
// } | ||
// expected := `{"name":"Joe"}` | ||
// if string(data) != expected { | ||
// t.Errorf("Expected %s got '%v'", expected, string(data)) | ||
func CreateTestHandler(testApp IApp, view CurrentView) http.HandlerFunc { | ||
v := testApp.GetView() | ||
var templates []string | ||
return v.handleFuncWrapper(templates, testApp.GetConfig(), *testApp.GetView(), view) | ||
} |
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
Oops, something went wrong.