pgweb/pkg/api/helpers_test.go
2016-02-26 08:48:55 -08:00

39 lines
899 B
Go

package api
import (
"net/http"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_desanitize64(t *testing.T) {
examples := map[string]string{
"test": "test",
"test+test+": "test-test-",
"test/test/": "test_test_",
"test=test==": "test.test..",
}
for expected, example := range examples {
assert.Equal(t, expected, desanitize64(example))
}
}
func Test_cleanQuery(t *testing.T) {
assert.Equal(t, "a\nb\nc", cleanQuery("a\nb\nc"))
assert.Equal(t, "", cleanQuery("--something"))
assert.Equal(t, "test", cleanQuery("--test\ntest\n -- test\n"))
}
func Test_getSessionId(t *testing.T) {
req := &http.Request{Header: http.Header{}}
req.Header.Add("x-session-id", "token")
assert.Equal(t, "token", getSessionId(req))
req = &http.Request{}
req.URL, _ = url.Parse("http://foobar/?_session_id=token")
assert.Equal(t, "token", getSessionId(req))
}