Skip to content

Commit 8305aa8

Browse files
authored
Merge pull request #264 from EasyPost/fix_coverage_layout
chore: overhaul test file layout to and fix coverage
2 parents b132467 + ac0f30f commit 8305aa8

File tree

188 files changed

+451
-529
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+451
-529
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
.env
21
.DS_Store
2+
.env
33
.idea/
4-
vendor/
5-
covprofile
4+
*.out
65
/.golangci.yml
6+
covprofile
7+
vendor/

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ clean:
1717

1818
## coverage - Get test coverage and open it in a browser
1919
coverage:
20-
go clean -testcache && GOEXPERIMENT=nocoverageredesign go test ./tests -v -coverprofile=covprofile -coverpkg=./... && go tool cover -html=covprofile
20+
go clean -testcache
21+
go test -coverprofile=covprofile ./...
22+
@statement_cov=$$(go tool cover -func=covprofile | grep total: | awk '{print substr($$NF, 1, length($$NF)-1)}'); \
23+
if [ $$(echo "$$statement_cov < 78.0" | bc) -eq 1 ]; then \
24+
echo "Tests passed but statement coverage failed with coverage: $$statement_cov"; \
25+
exit 1; \
26+
fi
27+
go tool cover -html=covprofile
2128

2229
## init-examples-submodule - Initialize the examples submodule
2330
init-examples-submodule:
@@ -53,7 +60,7 @@ scan:
5360

5461
## test - Test the project
5562
test:
56-
go clean -testcache && go test ./tests -v
63+
go clean -testcache && go test ./... -v
5764

5865
## tidy - Tidies up the vendor directory
5966
tidy:
Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
package easypost_test
1+
package easypost
22

33
import (
44
"errors"
55
"reflect"
66
"strings"
7-
8-
"github.com/EasyPost/easypost-go/v5"
97
)
108

119
func (c *ClientTests) TestAddressCreate() {
@@ -18,7 +16,7 @@ func (c *ClientTests) TestAddressCreate() {
1816
)
1917
require.NoError(err)
2018

21-
assert.Equal(reflect.TypeOf(&easypost.Address{}), reflect.TypeOf(address))
19+
assert.Equal(reflect.TypeOf(&Address{}), reflect.TypeOf(address))
2220
assert.True(strings.HasPrefix(address.ID, "adr_"))
2321
assert.Equal("388 Townsend St", address.Street1)
2422
}
@@ -29,13 +27,13 @@ func (c *ClientTests) TestAddressCreateVerifyStrict() {
2927

3028
address, err := client.CreateAddress(
3129
c.fixture.CaAddress1(),
32-
&easypost.CreateAddressOptions{
30+
&CreateAddressOptions{
3331
VerifyStrict: true,
3432
},
3533
)
3634
require.NoError(err)
3735

38-
assert.Equal(reflect.TypeOf(&easypost.Address{}), reflect.TypeOf(address))
36+
assert.Equal(reflect.TypeOf(&Address{}), reflect.TypeOf(address))
3937
assert.True(strings.HasPrefix(address.ID, "adr_"))
4038
assert.Equal("388 TOWNSEND ST APT 20", address.Street1)
4139
}
@@ -53,7 +51,7 @@ func (c *ClientTests) TestAddressRetrieve() {
5351
retrievedAddress, err := client.GetAddress(address.ID)
5452
require.NoError(err)
5553

56-
assert.Equal(reflect.TypeOf(&easypost.Address{}), reflect.TypeOf(retrievedAddress))
54+
assert.Equal(reflect.TypeOf(&Address{}), reflect.TypeOf(retrievedAddress))
5755
assert.Equal(address, retrievedAddress)
5856
}
5957

@@ -62,7 +60,7 @@ func (c *ClientTests) TestAddressAll() {
6260
assert, require := c.Assert(), c.Require()
6361

6462
addresses, err := client.ListAddresses(
65-
&easypost.ListOptions{
63+
&ListOptions{
6664
PageSize: c.fixture.pageSize(),
6765
},
6866
)
@@ -71,7 +69,7 @@ func (c *ClientTests) TestAddressAll() {
7169
assert.LessOrEqual(len(addresses.Addresses), c.fixture.pageSize())
7270
assert.NotNil(addresses.HasMore)
7371
for _, address := range addresses.Addresses {
74-
assert.Equal(reflect.TypeOf(&easypost.Address{}), reflect.TypeOf(address))
72+
assert.Equal(reflect.TypeOf(&Address{}), reflect.TypeOf(address))
7573
}
7674
}
7775

@@ -80,7 +78,7 @@ func (c *ClientTests) TestAddressGetNextPage() {
8078
assert, require := c.Assert(), c.Require()
8179

8280
firstPage, err := client.ListAddresses(
83-
&easypost.ListOptions{
81+
&ListOptions{
8482
PageSize: c.fixture.pageSize(),
8583
},
8684
)
@@ -98,7 +96,7 @@ func (c *ClientTests) TestAddressGetNextPage() {
9896
}
9997
}()
10098
if err != nil {
101-
var endOfPaginationErr *easypost.EndOfPaginationError
99+
var endOfPaginationErr *EndOfPaginationError
102100
if errors.As(err, &endOfPaginationErr) {
103101
assert.Equal(err.Error(), endOfPaginationErr.Error())
104102
return
@@ -114,14 +112,14 @@ func (c *ClientTests) TestAddressCreateVerify() {
114112

115113
address, err := client.CreateAddress(
116114
c.fixture.IncorrectAddress(),
117-
&easypost.CreateAddressOptions{
115+
&CreateAddressOptions{
118116
Verify: true,
119117
},
120118
)
121119

122120
// Does return an address from CreateAddress even if requested verification fails
123121
require.NoError(err)
124-
assert.Equal(reflect.TypeOf(&easypost.Address{}), reflect.TypeOf(address))
122+
assert.Equal(reflect.TypeOf(&Address{}), reflect.TypeOf(address))
125123

126124
// Delivery verification assertions
127125
deliveryVerification := address.Verifications.Delivery
@@ -151,17 +149,17 @@ func (c *ClientTests) TestAddressCreateAndVerify() {
151149
// Creating normally (without specifying "verify") will make the address, perform no verifications
152150
address, err := client.CreateAddress(
153151
c.fixture.IncorrectAddress(),
154-
&easypost.CreateAddressOptions{},
152+
&CreateAddressOptions{},
155153
)
156154
require.NoError(err)
157155

158-
assert.Equal(reflect.TypeOf(&easypost.Address{}), reflect.TypeOf(address))
156+
assert.Equal(reflect.TypeOf(&Address{}), reflect.TypeOf(address))
159157
assert.Nil(address.Verifications.Delivery)
160158

161159
// Creating with verify would attempt to make the address and perform verifications
162160
address, err = client.CreateAndVerifyAddress(
163161
c.fixture.IncorrectAddress(),
164-
&easypost.CreateAddressOptions{
162+
&CreateAddressOptions{
165163
Verify: true,
166164
},
167165
)
@@ -184,7 +182,7 @@ func (c *ClientTests) TestAddressVerify() {
184182
verifiedAddress, err := client.VerifyAddress(address.ID)
185183
require.NoError(err)
186184

187-
assert.Equal(reflect.TypeOf(&easypost.Address{}), reflect.TypeOf(verifiedAddress))
185+
assert.Equal(reflect.TypeOf(&Address{}), reflect.TypeOf(verifiedAddress))
188186
assert.True(strings.HasPrefix(verifiedAddress.ID, "adr_"))
189187
assert.Equal("388 TOWNSEND ST APT 20", verifiedAddress.Street1)
190188
}
@@ -196,14 +194,14 @@ func (c *ClientTests) TestAddressCreateVerifyCarrier() {
196194

197195
address, err := client.CreateAddress(
198196
c.fixture.IncorrectAddress(),
199-
&easypost.CreateAddressOptions{
197+
&CreateAddressOptions{
200198
Verify: true,
201199
VerifyCarrier: "UPS",
202200
},
203201
)
204202

205203
require.NoError(err)
206-
assert.Equal(reflect.TypeOf(&easypost.Address{}), reflect.TypeOf(address))
204+
assert.Equal(reflect.TypeOf(&Address{}), reflect.TypeOf(address))
207205

208206
deliveryVerification := address.Verifications.Delivery
209207
deliveryError := deliveryVerification.Errors[0]
@@ -220,13 +218,13 @@ func (c *ClientTests) TestAddressCreateAndVerifyCarrier() {
220218

221219
address, err := client.CreateAndVerifyAddress(
222220
c.fixture.IncorrectAddress(),
223-
&easypost.CreateAddressOptions{
221+
&CreateAddressOptions{
224222
VerifyCarrier: "UPS",
225223
},
226224
)
227225

228226
require.NoError(err)
229-
assert.Equal(reflect.TypeOf(&easypost.Address{}), reflect.TypeOf(address))
227+
assert.Equal(reflect.TypeOf(&Address{}), reflect.TypeOf(address))
230228

231229
deliveryVerification := address.Verifications.Delivery
232230
deliveryError := deliveryVerification.Errors[0]
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
package easypost_test
1+
package easypost
22

33
import (
44
"reflect"
5-
6-
"github.com/EasyPost/easypost-go/v5"
75
)
86

97
func (c *ClientTests) TestApiKeysAll() {
@@ -39,5 +37,5 @@ func (c *ClientTests) TestApiKeysForChildUser() {
3937
require.Error(err)
4038

4139
assert.Nil(apiKeys)
42-
assert.Equal(reflect.TypeOf(&easypost.FilteringError{}), reflect.TypeOf(err))
40+
assert.Equal(reflect.TypeOf(&FilteringError{}), reflect.TypeOf(err))
4341
}
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package easypost_test
1+
package easypost
22

33
import (
44
"errors"
@@ -7,8 +7,6 @@ import (
77
"reflect"
88
"strings"
99
"time"
10-
11-
"github.com/EasyPost/easypost-go/v5"
1210
)
1311

1412
func (c *ClientTests) TestBatchCreate() {
@@ -20,7 +18,7 @@ func (c *ClientTests) TestBatchCreate() {
2018
)
2119
require.NoError(err)
2220

23-
assert.Equal(reflect.TypeOf(&easypost.Batch{}), reflect.TypeOf(batch))
21+
assert.Equal(reflect.TypeOf(&Batch{}), reflect.TypeOf(batch))
2422
assert.True(strings.HasPrefix(batch.ID, "batch_"))
2523
assert.NotNil(batch.Shipments)
2624
}
@@ -37,7 +35,7 @@ func (c *ClientTests) TestBatchRetrieve() {
3735
retrievedBatch, err := client.GetBatch(batch.ID)
3836
require.NoError(err)
3937

40-
assert.Equal(reflect.TypeOf(&easypost.Batch{}), reflect.TypeOf(retrievedBatch))
38+
assert.Equal(reflect.TypeOf(&Batch{}), reflect.TypeOf(retrievedBatch))
4139
assert.Equal(batch.ID, retrievedBatch.ID)
4240
}
4341

@@ -46,7 +44,7 @@ func (c *ClientTests) TestBatchAll() {
4644
assert, require := c.Assert(), c.Require()
4745

4846
batches, err := client.ListBatches(
49-
&easypost.ListOptions{
47+
&ListOptions{
5048
PageSize: c.fixture.pageSize(),
5149
},
5250
)
@@ -55,7 +53,7 @@ func (c *ClientTests) TestBatchAll() {
5553
assert.LessOrEqual(len(batches.Batch), c.fixture.pageSize())
5654
assert.NotNil(batches.HasMore)
5755
for _, batch := range batches.Batch {
58-
assert.Equal(reflect.TypeOf(&easypost.Batch{}), reflect.TypeOf(batch))
56+
assert.Equal(reflect.TypeOf(&Batch{}), reflect.TypeOf(batch))
5957
}
6058
}
6159

@@ -71,7 +69,7 @@ func (c *ClientTests) TestBatchBuy() {
7169
boughtBatch, err := client.BuyBatch(batch.ID)
7270
require.NoError(err)
7371

74-
assert.Equal(reflect.TypeOf(&easypost.Batch{}), reflect.TypeOf(boughtBatch))
72+
assert.Equal(reflect.TypeOf(&Batch{}), reflect.TypeOf(boughtBatch))
7573
assert.Equal(1, boughtBatch.NumShipments)
7674
}
7775

@@ -97,7 +95,7 @@ func (c *ClientTests) TestBatchCreateScanForm() {
9795
require.NoError(err)
9896

9997
// We can't assert anything meaningful here because the scanform gets queued for generation and may not be immediately available
100-
assert.Equal(reflect.TypeOf(&easypost.Batch{}), reflect.TypeOf(batchWithScanForm))
98+
assert.Equal(reflect.TypeOf(&Batch{}), reflect.TypeOf(batchWithScanForm))
10199
}
102100

103101
func (c *ClientTests) TestBatchAddRemoveShipment() {
@@ -145,5 +143,5 @@ func (c *ClientTests) TestBatchLabel() {
145143
require.NoError(err)
146144

147145
// We can't assert anything meaningful here because the label gets queued for generation and may not be immediately available
148-
assert.Equal(reflect.TypeOf(&easypost.Batch{}), reflect.TypeOf(batchWithLabel))
146+
assert.Equal(reflect.TypeOf(&Batch{}), reflect.TypeOf(batchWithLabel))
149147
}

0 commit comments

Comments
 (0)