Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

New network test + fix import

Cette révision appartient à :
akuma06 2017-07-30 02:16:14 +02:00
Parent 97538f14c3
révision 5c375db112
2 fichiers modifiés avec 60 ajouts et 1 suppressions

Voir le fichier

@ -9,13 +9,13 @@ import (
"github.com/NyaaPantsu/nyaa/controllers/router"
"github.com/NyaaPantsu/nyaa/models"
"github.com/NyaaPantsu/nyaa/models/tags"
"github.com/NyaaPantsu/nyaa/models/torrents"
"github.com/NyaaPantsu/nyaa/templates"
msg "github.com/NyaaPantsu/nyaa/utils/messages"
"github.com/NyaaPantsu/nyaa/utils/validator"
"github.com/NyaaPantsu/nyaa/utils/validator/tags"
"github.com/gin-gonic/gin"
"github.com/NyaaPantsu/nyaa/models/tag"
)
func postTag(c *gin.Context, torrent *models.Torrent, user *models.User) {

59
network_test.go Fichier normal
Voir le fichier

@ -0,0 +1,59 @@
package main
import (
"net/http"
"testing"
"fmt"
"io/ioutil"
"net/http/httptest"
"sync"
"github.com/NyaaPantsu/nyaa/config"
)
type MyHandler struct {
sync.Mutex
count int
}
func (h *MyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var count int
h.Lock()
h.count++
count = h.count
h.Unlock()
fmt.Fprintf(w, "Visitor count: %d.", count)
}
func TestCreateHTTPListener(t *testing.T) {
// Set up server,
conf := config.Get()
testListener, err := CreateHTTPListener(conf)
if err != nil {
t.Error(err)
}
srv := httptest.NewUnstartedServer(&MyHandler{})
srv.Listener = testListener
defer srv.Close()
srv.Start()
for _, i := range []int{1, 2} {
resp, err := http.Get(srv.URL)
if err != nil {
t.Fatal(err)
}
if resp.StatusCode != 200 {
t.Fatalf("Received non-200 response: %d\n", resp.StatusCode)
}
expected := fmt.Sprintf("Visitor count: %d.", i)
actual, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}
if expected != string(actual) {
t.Errorf("Expected the message '%s', got '%s'\n", expected, string(actual))
}
}
}