-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdk_test.go
63 lines (55 loc) · 1.49 KB
/
sdk_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
package sdk
import (
"net/http"
"net/http/httptest"
"net/url"
"testing"
"github.com/gorilla/mux"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
const (
defaultBaseURL = "/api/"
defaultAuthBaseURL = defaultBaseURL + "auth/"
defaultDataBaseURL = defaultBaseURL + "data/"
defaultMetaDataBaseURL = defaultBaseURL + "metadata/"
)
type TestSuite struct {
suite.Suite
SDK *SDK
Router *mux.Router
Server *httptest.Server
}
func Test(t *testing.T) {
suite.Run(t, new(TestSuite))
}
func (suite *TestSuite) SetupTest() {
router := mux.NewRouter()
server := httptest.NewServer(router)
// Make a transport that reroutes all traffic to the example server
transport := &http.Transport{
Proxy: func(req *http.Request) (*url.URL, error) {
return url.Parse(server.URL)
},
}
urls := &ServiceEndpoints{}
urls.AuthServiceBaseURL = server.URL + defaultAuthBaseURL
urls.DataServiceBaseURL = server.URL + defaultDataBaseURL
urls.MetaDataServiceBaseURL = server.URL + defaultMetaDataBaseURL
httpClient := &http.Client{Transport: transport}
sdk := New(urls, httpClient)
suite.Router = router
suite.Server = server
suite.SDK = sdk
}
func (suite *TestSuite) TeardownTest() {
defer suite.Server.Close()
}
func (suite *TestSuite) TestNew() {
urls := &ServiceEndpoints{}
urls.AuthServiceBaseURL = defaultAuthBaseURL
urls.DataServiceBaseURL = defaultBaseURL
urls.MetaDataServiceBaseURL = defaultBaseURL
sdk := New(urls, nil)
require.NotNil(suite.T(), sdk)
}