-
Notifications
You must be signed in to change notification settings - Fork 27
/
export_test.go
61 lines (51 loc) · 1.28 KB
/
export_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
package postgrest
import (
"os"
"regexp"
"testing"
)
const urlEnv = "POSTGREST_URL"
const apiKeyEnv = "API_KEY"
// If false, mock responses with httpmock. If true, use POSTGREST_URL (and
// optionally, API_KEY for Supabase), to run tests against an actual Postgres
// instance.
var mockResponses = false
var mockPath *regexp.Regexp
type TestResult struct {
ID float64 `json:"id"`
Name string `name:"sean"`
Email string `email:"[email protected]"`
}
// A mock table/result set.
var users = []map[string]interface{}{
{
"id": float64(1), // numeric types are returned as float64s
"name": "sean",
"email": "[email protected]",
},
{
"id": float64(2),
"name": "patti",
"email": "[email protected]",
},
}
func createClient(t *testing.T) *Client {
// If a POSTGREST_URL environment variable is specified, we'll use that
// to test against real endpoints.
url := os.Getenv(urlEnv)
if url == "" {
url = "http://mock.xyz"
mockResponses = true
var err error
mockPath, err = regexp.Compile(regexp.QuoteMeta(url) + "?.*")
if err != nil {
t.Fatal(err)
}
}
headers := make(map[string]string)
if apiKeyEnv != "" {
// If the API_KEY env is specified, we'll use it to auth with Supabase.
headers["apikey"] = os.Getenv(apiKeyEnv)
}
return NewClient(url, "", headers)
}