mirror of
https://github.com/1f349/violet.git
synced 2024-11-13 23:11:36 +00:00
26 lines
678 B
Go
26 lines
678 B
Go
package target
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestRedirect_ServeHTTP(t *testing.T) {
|
|
a := []struct {
|
|
Redirect
|
|
target string
|
|
}{
|
|
{Redirect{Dst: "example.com/bye", Flags: FlagAbs, Code: http.StatusFound}, "https://example.com/bye"},
|
|
{Redirect{Dst: "example.com/bye", Code: http.StatusFound}, "https://example.com/bye/hello/world"},
|
|
}
|
|
for _, i := range a {
|
|
res := httptest.NewRecorder()
|
|
req := httptest.NewRequest(http.MethodGet, "https://www.example.com/hello/world", nil)
|
|
i.ServeHTTP(res, req)
|
|
assert.Equal(t, i.Code, res.Code)
|
|
assert.Equal(t, i.target, res.Header().Get("Location"))
|
|
}
|
|
}
|