Add decode,handle_test.

This commit is contained in:
Naoki Kosaka 2018-11-10 00:36:46 +09:00
parent 9a77f07db1
commit da4eb17551
2 changed files with 41 additions and 1 deletions

37
decode_test.go Normal file
View File

@ -0,0 +1,37 @@
package main
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestHandleInboxNoSignature(t *testing.T) {
s := httptest.NewServer(http.HandlerFunc(handleInbox))
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(handleInbox))
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")
}
}

View File

@ -10,7 +10,7 @@ import (
"testing"
"github.com/yukimochi/Activity-Relay/ActivityPub"
keyloader "github.com/yukimochi/Activity-Relay/KeyLoader"
"github.com/yukimochi/Activity-Relay/KeyLoader"
)
func TestMain(m *testing.M) {
@ -60,6 +60,7 @@ func TestHandleWebfingerGet(t *testing.T) {
t.Fatalf("WebfingerResource's Host not valid.")
}
}
func TestHandleWebfingerGetBadResource(t *testing.T) {
s := httptest.NewServer(http.HandlerFunc(handleWebfinger))
defer s.Close()
@ -77,6 +78,7 @@ func TestHandleWebfingerGetBadResource(t *testing.T) {
t.Fatalf("Failed - StatusCode is not 404.")
}
}
func TestHandleWebfingerInvalidMethod(t *testing.T) {
s := httptest.NewServer(http.HandlerFunc(handleWebfinger))
defer s.Close()
@ -91,6 +93,7 @@ func TestHandleWebfingerInvalidMethod(t *testing.T) {
t.Fatalf("Failed - StatusCode is not 400.")
}
}
func TestHandleActorGet(t *testing.T) {
s := httptest.NewServer(http.HandlerFunc(handleActor))
defer s.Close()