Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.env
.DS_Store
.env
.idea/
vendor/
covprofile
*.out
/.golangci.yml
covprofile
vendor/
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ clean:

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

## init-examples-submodule - Initialize the examples submodule
init-examples-submodule:
Expand Down Expand Up @@ -53,7 +60,7 @@ scan:

## test - Test the project
test:
go clean -testcache && go test ./tests -v
go clean -testcache && go test ./... -v

## tidy - Tidies up the vendor directory
tidy:
Expand Down
40 changes: 19 additions & 21 deletions tests/address_test.go → address_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package easypost_test
package easypost

import (
"errors"
"reflect"
"strings"

"github.com/EasyPost/easypost-go/v5"
)

func (c *ClientTests) TestAddressCreate() {
Expand All @@ -18,7 +16,7 @@ func (c *ClientTests) TestAddressCreate() {
)
require.NoError(err)

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

address, err := client.CreateAddress(
c.fixture.CaAddress1(),
&easypost.CreateAddressOptions{
&CreateAddressOptions{
VerifyStrict: true,
},
)
require.NoError(err)

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

assert.Equal(reflect.TypeOf(&easypost.Address{}), reflect.TypeOf(retrievedAddress))
assert.Equal(reflect.TypeOf(&Address{}), reflect.TypeOf(retrievedAddress))
assert.Equal(address, retrievedAddress)
}

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

addresses, err := client.ListAddresses(
&easypost.ListOptions{
&ListOptions{
PageSize: c.fixture.pageSize(),
},
)
Expand All @@ -71,7 +69,7 @@ func (c *ClientTests) TestAddressAll() {
assert.LessOrEqual(len(addresses.Addresses), c.fixture.pageSize())
assert.NotNil(addresses.HasMore)
for _, address := range addresses.Addresses {
assert.Equal(reflect.TypeOf(&easypost.Address{}), reflect.TypeOf(address))
assert.Equal(reflect.TypeOf(&Address{}), reflect.TypeOf(address))
}
}

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

firstPage, err := client.ListAddresses(
&easypost.ListOptions{
&ListOptions{
PageSize: c.fixture.pageSize(),
},
)
Expand All @@ -98,7 +96,7 @@ func (c *ClientTests) TestAddressGetNextPage() {
}
}()
if err != nil {
var endOfPaginationErr *easypost.EndOfPaginationError
var endOfPaginationErr *EndOfPaginationError
if errors.As(err, &endOfPaginationErr) {
assert.Equal(err.Error(), endOfPaginationErr.Error())
return
Expand All @@ -114,14 +112,14 @@ func (c *ClientTests) TestAddressCreateVerify() {

address, err := client.CreateAddress(
c.fixture.IncorrectAddress(),
&easypost.CreateAddressOptions{
&CreateAddressOptions{
Verify: true,
},
)

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

// Delivery verification assertions
deliveryVerification := address.Verifications.Delivery
Expand Down Expand Up @@ -151,17 +149,17 @@ func (c *ClientTests) TestAddressCreateAndVerify() {
// Creating normally (without specifying "verify") will make the address, perform no verifications
address, err := client.CreateAddress(
c.fixture.IncorrectAddress(),
&easypost.CreateAddressOptions{},
&CreateAddressOptions{},
)
require.NoError(err)

assert.Equal(reflect.TypeOf(&easypost.Address{}), reflect.TypeOf(address))
assert.Equal(reflect.TypeOf(&Address{}), reflect.TypeOf(address))
assert.Nil(address.Verifications.Delivery)

// Creating with verify would attempt to make the address and perform verifications
address, err = client.CreateAndVerifyAddress(
c.fixture.IncorrectAddress(),
&easypost.CreateAddressOptions{
&CreateAddressOptions{
Verify: true,
},
)
Expand All @@ -184,7 +182,7 @@ func (c *ClientTests) TestAddressVerify() {
verifiedAddress, err := client.VerifyAddress(address.ID)
require.NoError(err)

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

address, err := client.CreateAddress(
c.fixture.IncorrectAddress(),
&easypost.CreateAddressOptions{
&CreateAddressOptions{
Verify: true,
VerifyCarrier: "UPS",
},
)

require.NoError(err)
assert.Equal(reflect.TypeOf(&easypost.Address{}), reflect.TypeOf(address))
assert.Equal(reflect.TypeOf(&Address{}), reflect.TypeOf(address))

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

address, err := client.CreateAndVerifyAddress(
c.fixture.IncorrectAddress(),
&easypost.CreateAddressOptions{
&CreateAddressOptions{
VerifyCarrier: "UPS",
},
)

require.NoError(err)
assert.Equal(reflect.TypeOf(&easypost.Address{}), reflect.TypeOf(address))
assert.Equal(reflect.TypeOf(&Address{}), reflect.TypeOf(address))

deliveryVerification := address.Verifications.Delivery
deliveryError := deliveryVerification.Errors[0]
Expand Down
6 changes: 2 additions & 4 deletions tests/api_key_test.go → api_key_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package easypost_test
package easypost

import (
"reflect"

"github.com/EasyPost/easypost-go/v5"
)

func (c *ClientTests) TestApiKeysAll() {
Expand Down Expand Up @@ -39,5 +37,5 @@ func (c *ClientTests) TestApiKeysForChildUser() {
require.Error(err)

assert.Nil(apiKeys)
assert.Equal(reflect.TypeOf(&easypost.FilteringError{}), reflect.TypeOf(err))
assert.Equal(reflect.TypeOf(&FilteringError{}), reflect.TypeOf(err))
}
18 changes: 8 additions & 10 deletions tests/batch_test.go → batch_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package easypost_test
package easypost

import (
"errors"
Expand All @@ -7,8 +7,6 @@ import (
"reflect"
"strings"
"time"

"github.com/EasyPost/easypost-go/v5"
)

func (c *ClientTests) TestBatchCreate() {
Expand All @@ -20,7 +18,7 @@ func (c *ClientTests) TestBatchCreate() {
)
require.NoError(err)

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

assert.Equal(reflect.TypeOf(&easypost.Batch{}), reflect.TypeOf(retrievedBatch))
assert.Equal(reflect.TypeOf(&Batch{}), reflect.TypeOf(retrievedBatch))
assert.Equal(batch.ID, retrievedBatch.ID)
}

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

batches, err := client.ListBatches(
&easypost.ListOptions{
&ListOptions{
PageSize: c.fixture.pageSize(),
},
)
Expand All @@ -55,7 +53,7 @@ func (c *ClientTests) TestBatchAll() {
assert.LessOrEqual(len(batches.Batch), c.fixture.pageSize())
assert.NotNil(batches.HasMore)
for _, batch := range batches.Batch {
assert.Equal(reflect.TypeOf(&easypost.Batch{}), reflect.TypeOf(batch))
assert.Equal(reflect.TypeOf(&Batch{}), reflect.TypeOf(batch))
}
}

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

assert.Equal(reflect.TypeOf(&easypost.Batch{}), reflect.TypeOf(boughtBatch))
assert.Equal(reflect.TypeOf(&Batch{}), reflect.TypeOf(boughtBatch))
assert.Equal(1, boughtBatch.NumShipments)
}

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

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

func (c *ClientTests) TestBatchAddRemoveShipment() {
Expand Down Expand Up @@ -145,5 +143,5 @@ func (c *ClientTests) TestBatchLabel() {
require.NoError(err)

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