This repository has been archived by the owner on Jul 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathschemas_test.go
75 lines (65 loc) · 2.75 KB
/
schemas_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package controllers
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/gorilla/mux"
"github.com/prest/adapters/postgres"
"github.com/prest/config"
)
func TestGetSchemas(t *testing.T) {
config.Load()
postgres.Load()
var testCases = []struct {
description string
url string
method string
status int
body string
}{
{"Get schemas without custom where clause", "/schemas", "GET", http.StatusOK, "[{\"schema_name\":\"information_schema\"}, \n {\"schema_name\":\"pg_catalog\"}, \n {\"schema_name\":\"pg_temp_1\"}, \n {\"schema_name\":\"pg_toast\"}, \n {\"schema_name\":\"pg_toast_temp_1\"}, \n {\"schema_name\":\"public\"}]"},
{"Get schemas with custom where clause", "/schemas?schema_name=$eq.public", "GET", http.StatusOK, "[{\"schema_name\":\"public\"}]"},
{"Get schemas with custom order clause", "/schemas?schema_name=$eq.public&_order=schema_name", "GET", http.StatusOK, "[{\"schema_name\":\"public\"}]"},
{"Get schemas with custom where clause and pagination", "/schemas?schema_name=$eq.public&_page=1&_page_size=20", "GET", http.StatusOK, "[{\"schema_name\":\"public\"}]"},
{"Get schemas with COUNT clause", "/schemas?_count=*", "GET", http.StatusOK, "[{\"count\":6}]"},
{"Get schemas with custom where invalid clause", "/schemas?0schema_name=$eq.public", "GET", http.StatusBadRequest, "invalid identifier: 0schema_name\n"},
{"Get schemas with noexistent column", "/schemas?schematame=$eq.test", "GET", http.StatusBadRequest, "pq: column \"schematame\" does not exist\n"},
{"Get schemas with distinct clause", "/schemas?schema_name=$eq.public&_distinct=true", "GET", http.StatusOK, "[{\"schema_name\":\"public\"}]"},
}
router := mux.NewRouter()
router.HandleFunc("/schemas", GetSchemas).Methods("GET")
server := httptest.NewServer(router)
defer server.Close()
for _, tc := range testCases {
t.Log(tc.description)
doRequest(t, server.URL+tc.url, nil, tc.method, tc.status, "GetSchemas", tc.body)
}
}
func TestVersionDependentGetSchemas(t *testing.T) {
//This test supports error messages from different versions of Go.
var testCases = []struct {
description string
url string
method string
status int
body []string
}{
{"Get schemas with custom where and pagination invalid",
"/schemas?schema_name=$eq.public&_page=A",
"GET",
http.StatusBadRequest,
[]string{
"strconv.ParseInt: parsing \"A\": invalid syntax\n",
"strconv.Atoi: parsing \"A\": invalid syntax\n",
},
},
}
router := mux.NewRouter()
router.HandleFunc("/schemas", GetSchemas).Methods("GET")
server := httptest.NewServer(router)
defer server.Close()
for _, tc := range testCases {
t.Log(tc.description)
doRequest(t, server.URL+tc.url, nil, tc.method, tc.status, "GetSchemas", tc.body...)
}
}