owl-blogs/cmd/owl/web/rss_test.go

44 lines
1.1 KiB
Go
Raw Normal View History

2022-09-05 18:34:24 +00:00
package web_test
2022-08-16 18:36:05 +00:00
import (
"h4kor/owl-blogs"
2022-09-05 18:34:24 +00:00
main "h4kor/owl-blogs/cmd/owl/web"
2022-08-16 18:36:05 +00:00
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestMultiUserUserRssIndexHandler(t *testing.T) {
repo := getTestRepo(owl.RepoConfig{})
2022-08-16 18:36:05 +00:00
user, _ := repo.CreateUser("test-1")
user.CreateNewPost("post-1")
// Create Request and Response
req, err := http.NewRequest("GET", user.UrlPath()+"index.xml", nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
router := main.Router(&repo)
router.ServeHTTP(rr, req)
// Check the status code is what we expect.
if status := rr.Code; status != http.StatusOK {
t.Errorf("handler returned wrong status code: got %v want %v",
status, http.StatusOK)
}
// Check the response Content-Type is what we expect.
if !strings.Contains(rr.Header().Get("Content-Type"), "application/rss+xml") {
t.Errorf("handler returned wrong Content-Type: got %v want %v",
rr.Header().Get("Content-Type"), "application/rss+xml")
}
// Check the response body contains names of users
if !strings.Contains(rr.Body.String(), "post-1") {
t.Error("post-1 not listed on index page. Got: ")
t.Error(rr.Body.String())
}
}