/
setup_test.go
50 lines (41 loc) · 985 Bytes
/
setup_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
package vismanet_test
import (
"context"
"log"
"net/url"
"os"
"testing"
vismanet "github.com/omniboost/go-visma.net-hrm-payroll"
)
var (
client *vismanet.Client
)
func TestMain(m *testing.M) {
baseURLString := os.Getenv("BASE_URL")
clientID := os.Getenv("CLIENT_ID")
clientSecret := os.Getenv("CLIENT_SECRET")
tenantID := os.Getenv("TENANT_ID")
tokenURL := os.Getenv("TOKEN_URL")
debug := os.Getenv("DEBUG")
oauthConfig := vismanet.NewOauth2Config(tenantID)
oauthConfig.ClientID = clientID
oauthConfig.ClientSecret = clientSecret
// set alternative token url
if tokenURL != "" {
oauthConfig.TokenURL = tokenURL
}
// get http client with automatic oauth logic
httpClient := oauthConfig.Client(context.Background())
client = vismanet.NewClient(httpClient)
if debug != "" {
client.SetDebug(true)
}
if baseURLString != "" {
baseURL, err := url.Parse(baseURLString)
if err != nil {
log.Fatal(err)
}
client.SetBaseURL(*baseURL)
}
m.Run()
}