additional test for not existing alias

This commit is contained in:
Niko Abeler 2022-08-06 20:18:49 +02:00
parent c50d3ee74c
commit a0f912d81a
1 changed files with 31 additions and 0 deletions

View File

@ -45,3 +45,34 @@ func TestRedirectOnAliases(t *testing.T) {
)
}
}
func TestNoRedirectOnNonExistingAliases(t *testing.T) {
repo := getTestRepo()
user, _ := repo.CreateUser("test-1")
post, _ := user.CreateNewPost("post-1")
content := "---\n"
content += "title: Test\n"
content += "aliases: \n"
content += " - /foo/bar\n"
content += " - /foo/baz\n"
content += "---\n"
content += "This is a test"
os.WriteFile(post.ContentFile(), []byte(content), 0644)
// Create Request and Response
req, err := http.NewRequest("GET", "/foo/bar2", 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.StatusNotFound {
t.Errorf("handler returned wrong status code: got %v want %v",
status, http.StatusNotFound)
}
}