-
Notifications
You must be signed in to change notification settings - Fork 1
/
functional_test.go
45 lines (40 loc) · 1 KB
/
functional_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
package main
import (
"github.com/jmoiron/sqlx"
"github.com/lestrrat-go/test-mysqld"
"os"
"testing"
"net/http"
"fmt"
"github.com/stretchr/testify/assert"
"github.com/avast/retry-go/v3"
)
func TestServer(t *testing.T) {
/* Set up MySQL */
mysqld, err := mysqltest.NewMysqld(nil)
if err != nil {
t.Fatalf("failed to start mysqld: %s", err)
}
db, err := sqlx.Open("mysql", mysqld.Datasource("test", "", "", 0))
if err != nil {
t.Fatalf("failed to open MySQL connection: %s", err)
}
/* Set up ENV variables */
os.Setenv("OAUTH_CLIENT_ID", "testVal")
os.Setenv("OAUTH_CLIENT_SECRET", "testVal")
os.Setenv("BASE_URL", "testVal")
os.Setenv("S3_REGION", "testVal")
os.Setenv("S3_AUTH_ID", "testVal")
os.Setenv("S3_SECRET", "testVal")
go main0(db)
var response *http.Response
retry.Do(func () error {
resp, err := http.Get("http://localhost:8080/healthcheck")
fmt.Println("{}, {}", resp, err)
if err == nil {
response = resp
}
return err
})
assert.Equal(t, response.StatusCode, 200)
}