-
Notifications
You must be signed in to change notification settings - Fork 0
/
semantics3_test.go
64 lines (52 loc) · 1.68 KB
/
semantics3_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
package semantics3
import (
"github.com/mrjones/oauth"
"github.com/stretchr/testify/assert"
"net/http"
"testing"
)
var mockExpected = make([]interface{}, 2)
//==================================================
// Base Mock OAuthConsumer
//==================================================
type MockOAuthConsumer struct{}
func (m MockOAuthConsumer) Get(string, map[string]string,
*oauth.AccessToken) (*http.Response, error) {
return nil, nil
}
//==================================================
// Tests
//==================================================
func Test_AddParams(t *testing.T) {
mockClient := &Client{}
params := map[string]interface{}{"key": "value"}
expected := `{"key":"value"}`
mockClient.AddParams(params)
assert.Equal(t, mockClient.dataquery, expected)
}
func Test_NewClient(t *testing.T) {
ret := NewClient("1", "2", "bags")
assert.Equal(t, ret.endpoint, "bags")
}
type MockOAuthConsumer_2 struct{ MockOAuthConsumer }
func (m MockOAuthConsumer_2) Get(baseURL string, params map[string]string,
token *oauth.AccessToken) (*http.Response, error) {
mockExpected[0] = baseURL
mockExpected[1] = params
return nil, nil
}
func Test_Get(t *testing.T) {
// should return error if oauth is not set
mockClient := &Client{}
ret, err := mockClient.Get()
assert.Nil(t, ret)
assert.Error(t, err)
// should return response
mockOAuth := &MockOAuthConsumer_2{}
mockClient = &Client{endpoint: "bags", dataquery: "query", oauth: mockOAuth}
ret, err = mockClient.Get()
assert.Nil(t, ret)
assert.Nil(t, err)
assert.Equal(t, mockExpected[0].(string), "https://api.semantics3.com/v1/bags")
assert.Equal(t, mockExpected[1].(map[string]string), map[string]string{"q": "query"})
}