<commit_before>package main

import (
	"net/http"
	"net/http/httptest"
	"testing"
)

var nopHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})

func TestFwdProtoHandler(t *testing.T) {
	prevForwardedProto := "fakeproto"
	prevForwardedPort := "8080"

	rec := httptest.NewRecorder()
	request, _ := http.NewRequest("GET", "http://test.com", nil)
	request.RemoteAddr = "1.2.3.4:5678"
	h := fwdProtoHandler{Handler: nopHandler, Proto: "https", Port: "443"}
	h.ServeHTTP(rec, request)
	if v := request.Header.Get("X-Forwarded-For"); v != "1.2.3.4" {
		t.Errorf("want X-Forwarded-For %s, got %s", "1.2.3.4", v)
	}
	if v := request.Header.Get("X-Forwarded-Proto"); v != "https" {
		t.Errorf("want X-Forwarded-Proto %s, got %s", "https", v)
	}
	if v := request.Header.Get("X-Forwarded-Port"); v != "443" {
		t.Errorf("want X-Forwarded-Port %s, got %s", "443", v)
	}

	// test with headers already set, make sure we append correctly
	rec = httptest.NewRecorder()
	request, _ = http.NewRequest("GET", "http://test.com", nil)
	request.Header.Set("X-Forwarded-Proto", prevForwardedProto)
	request.Header.Set("X-Forwarded-Port", prevForwardedPort)

	h.ServeHTTP(rec, request)
	want := prevForwardedProto + ", https"
	got := request.Header.Get("X-Forwarded-Proto")
	if want != got {
		t.Errorf("want X-Forwarded-Proto %q, got %q", want, got)
	}
	want = prevForwardedPort + ", 443"
	got = request.Header.Get("X-Forwarded-Port")
	if want != got {
		t.Errorf("want X-Forwarded-Port %q, got %q", want, got)
	}
}<commit_msg>router: switch fwdProtoHandler test to use gocheck<commit_after>package main

import (
	"net/http"
	"net/http/httptest"

	. "github.com/flynn/flynn/Godeps/_workspace/src/github.com/flynn/go-check"
)

var nopHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})

func (s *S) TestFwdProtoHandler(c *C) {
	prevForwardedProto := "fakeproto"
	prevForwardedPort := "8080"

	rec := httptest.NewRecorder()
	request, _ := http.NewRequest("GET", "http://test.com", nil)
	request.RemoteAddr = "1.2.3.4:5678"
	h := fwdProtoHandler{Handler: nopHandler, Proto: "https", Port: "443"}
	h.ServeHTTP(rec, request)
	c.Assert(request.Header.Get("X-Forwarded-For"), Equals, "1.2.3.4")
	c.Assert(request.Header.Get("X-Forwarded-Proto"), Equals, "https")
	c.Assert(request.Header.Get("X-Forwarded-Port"), Equals, "443")

	// test with headers already set, make sure we append correctly
	rec = httptest.NewRecorder()
	request, _ = http.NewRequest("GET", "http://test.com", nil)
	request.Header.Set("X-Forwarded-Proto", prevForwardedProto)
	request.Header.Set("X-Forwarded-Port", prevForwardedPort)

	h.ServeHTTP(rec, request)
	c.Assert(request.Header.Get("X-Forwarded-Proto"), Equals, prevForwardedProto+", https")
	c.Assert(request.Header.Get("X-Forwarded-Port"), Equals, prevForwardedPort+", 443")
}
{'fraction_non_alphanumeric': 0.18316831683168316, 'fraction_numerical': 0.020155586987270154, 'mean_word_length': 4.809034907597536, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 5, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7022943', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1071, 'n_words': 207}