forked from vickxxx/appstore
-
Notifications
You must be signed in to change notification settings - Fork 3
/
client_test.go
61 lines (52 loc) · 1.73 KB
/
client_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 appstore
import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"testing"
)
type ClientTestSuite struct {
suite.Suite
cfg *Config
testable *Client
}
func (suite *ClientTestSuite) SetupTest() {
suite.cfg = buildStubConfig()
suite.testable = NewClientFromConfig(suite.cfg, nil)
}
func (suite *ClientTestSuite) TestNewClientFromConfig() {
assert.NotEmpty(suite.T(), suite.testable.Cfg)
assert.NotEmpty(suite.T(), suite.testable.http)
assert.NotEmpty(suite.T(), suite.testable.auth)
assert.Empty(suite.T(), suite.testable.transport)
}
func (suite *ClientTestSuite) TestInitSuccess() {
err := suite.testable.Init()
assert.NoError(suite.T(), err)
assert.NotEmpty(suite.T(), suite.testable.Cfg)
assert.NotEmpty(suite.T(), suite.testable.http)
assert.NotEmpty(suite.T(), suite.testable.auth)
assert.NotEmpty(suite.T(), suite.testable.transport)
}
func (suite *ClientTestSuite) TestInitError() {
suite.testable.Cfg.PrivateKey = "stubs/auth/keys/fail.p8"
err := suite.testable.Init()
assert.Error(suite.T(), err)
assert.Equal(suite.T(), "client.init error: PrivateKey.DecodePem: AuthKey must be a valid .p8 PEM file", err.Error())
}
func (suite *ClientTestSuite) TestSalesReports() {
_ = suite.testable.Init()
result := suite.testable.SalesReports()
assert.NotEmpty(suite.T(), result)
assert.NotEmpty(suite.T(), result.config)
assert.NotEmpty(suite.T(), result.transport)
}
func (suite *ClientTestSuite) TestFinancialReports() {
_ = suite.testable.Init()
result := suite.testable.FinancesReports()
assert.NotEmpty(suite.T(), result)
assert.NotEmpty(suite.T(), result.config)
assert.NotEmpty(suite.T(), result.transport)
}
func TestClientTestSuite(t *testing.T) {
suite.Run(t, new(ClientTestSuite))
}