diff --git a/controllers/torrent/tag.go b/controllers/torrent/tag.go index 7ee60fd3..216d9c81 100644 --- a/controllers/torrent/tag.go +++ b/controllers/torrent/tag.go @@ -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) { diff --git a/network_test.go b/network_test.go new file mode 100644 index 00000000..fb93d492 --- /dev/null +++ b/network_test.go @@ -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)) + } + } +}