Activity-Relay/decode_test.go
2018-11-15 17:19:12 +09:00

42 lines
934 B
Go

package main
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestHandleInboxNoSignature(t *testing.T) {
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handleInbox(w, r, decodeActivity)
}))
defer s.Close()
req, _ := http.NewRequest("POST", s.URL, nil)
client := new(http.Client)
r, err := client.Do(req)
if err != nil {
t.Fatalf("Failed - " + err.Error())
}
if r.StatusCode != 400 {
t.Fatalf("Failed - StatusCode is not 400")
}
}
func TestHandleInboxInvalidMethod(t *testing.T) {
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
handleInbox(w, r, decodeActivity)
}))
defer s.Close()
req, _ := http.NewRequest("GET", s.URL, nil)
client := new(http.Client)
r, err := client.Do(req)
if err != nil {
t.Fatalf("Failed - " + err.Error())
}
if r.StatusCode != 404 {
t.Fatalf("Failed - StatusCode is not 404")
}
}