Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
[CI] Run goimports & audit in CI (#246)
Browse files Browse the repository at this point in the history
Install & run `goimports` within CI.
  • Loading branch information
natebrennand authored Oct 27, 2022
1 parent ff18214 commit 2f475fe
Show file tree
Hide file tree
Showing 44 changed files with 224 additions and 155 deletions.
15 changes: 15 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ jobs:
command: |
cd integration-tests
go test -v
- run:
name: Install goimports
command: |
go get golang.org/x/tools/cmd/[email protected]
- swissknife/fail_if_dirty:
pattern: ".*.go$"
invert-pattern: false
custom-error-message: Please run 'goimports -w -local github.com/BoltApp/sleet ./' and push up again
print-modified-files: true
steps-to-run:
- run:
name: Run goimports
command: |
cd ../
goimports -w -local github.com/BoltApp/sleet ./
- save_cache:
key: v1-pkg-cache
paths:
Expand Down
5 changes: 3 additions & 2 deletions gateways/adyen/adyen.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package adyen
import (
"net/http"

"github.com/BoltApp/sleet"
"github.com/BoltApp/sleet/common"
"github.com/adyen/adyen-go-api-library/v4/src/adyen"
adyen_common "github.com/adyen/adyen-go-api-library/v4/src/common"

"github.com/BoltApp/sleet"
"github.com/BoltApp/sleet/common"
)

// AdyenClient represents the authentication fields needed to make API Requests for a given environment
Expand Down
3 changes: 2 additions & 1 deletion gateways/adyen/environment.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package adyen

import (
"github.com/BoltApp/sleet/common"
adyen_common "github.com/adyen/adyen-go-api-library/v4/src/common"

"github.com/BoltApp/sleet/common"
)

// Environment translates a Sleet common environment into the adyen specific environment for the library
Expand Down
16 changes: 9 additions & 7 deletions gateways/adyen/request_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"regexp"
"strconv"

"github.com/BoltApp/sleet"
"github.com/BoltApp/sleet/common"
"github.com/adyen/adyen-go-api-library/v4/src/checkout"
"github.com/adyen/adyen-go-api-library/v4/src/payments"

"github.com/BoltApp/sleet"
"github.com/BoltApp/sleet/common"
)

const (
Expand All @@ -20,7 +21,7 @@ const (
// Options
const (
applePayTokenOption = "ApplePayToken"
shopperIPOption = "ShopperIP"
shopperIPOption = "ShopperIP"
)

// Shopper Interactions
Expand Down Expand Up @@ -62,7 +63,7 @@ func buildAuthRequest(authRequest *sleet.AuthorizationRequest, merchantAccount s
Currency: authRequest.Amount.Currency,
},
// Adyen requires a reference in request so this will panic if client doesn't pass it. Assuming this is good for now
Reference: *authRequest.ClientTransactionReference,
Reference: *authRequest.ClientTransactionReference,
MerchantAccount: merchantAccount,
MerchantOrderReference: authRequest.MerchantOrderReference,

Expand Down Expand Up @@ -120,7 +121,7 @@ func addPaymentSpecificFields(authRequest *sleet.AuthorizationRequest, request *
// Add PaymentMethod field
if authRequest.Options[applePayTokenOption] != nil {
request.PaymentMethod = map[string]interface{}{
"type": "applepay",
"type": "applepay",
"applePayToken": authRequest.Options[applePayTokenOption].(string),
}
} else {
Expand Down Expand Up @@ -273,8 +274,9 @@ func addIfNonEmpty(value string, key string, data *map[string]string) {
}

// extractAdyenStreetFormat extracts adyen street format from generic street address
// returns (streetNumber, streetName) format
// If address does not have leading street number, will return ("", street)
//
// returns (streetNumber, streetName) format
// If address does not have leading street number, will return ("", street)
func extractAdyenStreetFormat(streetAddress string) (string, string) {
streetExtraction := streetNumberRegex.FindStringSubmatch(streetAddress)
if streetExtraction == nil {
Expand Down
75 changes: 38 additions & 37 deletions gateways/adyen/request_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"strconv"
"testing"

"github.com/BoltApp/sleet"
"github.com/adyen/adyen-go-api-library/v4/src/checkout"
"github.com/go-test/deep"

"github.com/BoltApp/sleet"

"github.com/BoltApp/sleet/common"
sleet_testing "github.com/BoltApp/sleet/testing"
)
Expand Down Expand Up @@ -48,11 +49,11 @@ func TestBuildAuthRequest(t *testing.T) {
Value: 100,
},
BillingAddress: &checkout.Address{
City: *base.BillingAddress.Locality,
Country: *base.BillingAddress.CountryCode,
PostalCode: *base.BillingAddress.PostalCode,
StateOrProvince: *base.BillingAddress.RegionCode,
Street: "Railroad Street",
City: *base.BillingAddress.Locality,
Country: *base.BillingAddress.CountryCode,
PostalCode: *base.BillingAddress.PostalCode,
StateOrProvince: *base.BillingAddress.RegionCode,
Street: "Railroad Street",
HouseNumberOrName: "7683",
},
MerchantAccount: "merchant-account",
Expand Down Expand Up @@ -80,11 +81,11 @@ func TestBuildAuthRequest(t *testing.T) {
Value: 100,
},
BillingAddress: &checkout.Address{
City: *baseWithAydenData.BillingAddress.Locality,
Country: *baseWithAydenData.BillingAddress.CountryCode,
PostalCode: *baseWithAydenData.BillingAddress.PostalCode,
StateOrProvince: *baseWithAydenData.BillingAddress.RegionCode,
Street: "Railroad Street",
City: *baseWithAydenData.BillingAddress.Locality,
Country: *baseWithAydenData.BillingAddress.CountryCode,
PostalCode: *baseWithAydenData.BillingAddress.PostalCode,
StateOrProvince: *baseWithAydenData.BillingAddress.RegionCode,
Street: "Railroad Street",
HouseNumberOrName: "7683",
},
MerchantAccount: "merchant-account",
Expand All @@ -102,11 +103,11 @@ func TestBuildAuthRequest(t *testing.T) {
StorePaymentMethod: true,
ShopperReference: "test",
DeliveryAddress: &checkout.Address{
City: *baseWithAydenData.ShippingAddress.Locality,
Country: *baseWithAydenData.ShippingAddress.CountryCode,
PostalCode: *baseWithAydenData.ShippingAddress.PostalCode,
StateOrProvince: *baseWithAydenData.ShippingAddress.RegionCode,
Street: "Railroad Street",
City: *baseWithAydenData.ShippingAddress.Locality,
Country: *baseWithAydenData.ShippingAddress.CountryCode,
PostalCode: *baseWithAydenData.ShippingAddress.PostalCode,
StateOrProvince: *baseWithAydenData.ShippingAddress.RegionCode,
Street: "Railroad Street",
HouseNumberOrName: "7683",
},
ShopperEmail: *baseWithAydenData.BillingAddress.Email,
Expand All @@ -122,11 +123,11 @@ func TestBuildAuthRequest(t *testing.T) {
Value: 100,
},
BillingAddress: &checkout.Address{
City: *requestWithLevel3Data.BillingAddress.Locality,
Country: *requestWithLevel3Data.BillingAddress.CountryCode,
PostalCode: *requestWithLevel3Data.BillingAddress.PostalCode,
StateOrProvince: *requestWithLevel3Data.BillingAddress.RegionCode,
Street: "Railroad Street",
City: *requestWithLevel3Data.BillingAddress.Locality,
Country: *requestWithLevel3Data.BillingAddress.CountryCode,
PostalCode: *requestWithLevel3Data.BillingAddress.PostalCode,
StateOrProvince: *requestWithLevel3Data.BillingAddress.RegionCode,
Street: "Railroad Street",
HouseNumberOrName: "7683",
},
MerchantAccount: "merchant-account",
Expand Down Expand Up @@ -169,11 +170,11 @@ func TestBuildAuthRequest(t *testing.T) {
Value: 100,
},
BillingAddress: &checkout.Address{
City: *requestWithLevel3Data.BillingAddress.Locality,
Country: *requestWithLevel3Data.BillingAddress.CountryCode,
PostalCode: *requestWithLevel3Data.BillingAddress.PostalCode,
StateOrProvince: *requestWithLevel3Data.BillingAddress.RegionCode,
Street: "Railroad Street",
City: *requestWithLevel3Data.BillingAddress.Locality,
Country: *requestWithLevel3Data.BillingAddress.CountryCode,
PostalCode: *requestWithLevel3Data.BillingAddress.PostalCode,
StateOrProvince: *requestWithLevel3Data.BillingAddress.RegionCode,
Street: "Railroad Street",
HouseNumberOrName: "7683",
},
MerchantAccount: "merchant-account",
Expand Down Expand Up @@ -217,11 +218,11 @@ func TestBuildAuthRequest(t *testing.T) {
Value: 100,
},
BillingAddress: &checkout.Address{
City: *requestCitiPLCC.BillingAddress.Locality,
Country: *requestCitiPLCC.BillingAddress.CountryCode,
PostalCode: *requestCitiPLCC.BillingAddress.PostalCode,
StateOrProvince: *requestCitiPLCC.BillingAddress.RegionCode,
Street: "Railroad Street",
City: *requestCitiPLCC.BillingAddress.Locality,
Country: *requestCitiPLCC.BillingAddress.CountryCode,
PostalCode: *requestCitiPLCC.BillingAddress.PostalCode,
StateOrProvince: *requestCitiPLCC.BillingAddress.RegionCode,
Street: "Railroad Street",
HouseNumberOrName: "7683",
},
MerchantAccount: "merchant-account",
Expand Down Expand Up @@ -249,16 +250,16 @@ func TestBuildAuthRequest(t *testing.T) {
Value: 100,
},
BillingAddress: &checkout.Address{
City: *base.BillingAddress.Locality,
Country: *base.BillingAddress.CountryCode,
PostalCode: *base.BillingAddress.PostalCode,
StateOrProvince: *base.BillingAddress.RegionCode,
Street: "Railroad Street",
City: *base.BillingAddress.Locality,
Country: *base.BillingAddress.CountryCode,
PostalCode: *base.BillingAddress.PostalCode,
StateOrProvince: *base.BillingAddress.RegionCode,
Street: "Railroad Street",
HouseNumberOrName: "7683",
},
MerchantAccount: "merchant-account",
PaymentMethod: map[string]interface{}{
"type": "applepay",
"type": "applepay",
"applePayToken": "testApplePayToken",
},
ShopperInteraction: "ContAuth",
Expand Down
3 changes: 2 additions & 1 deletion gateways/adyen/rtau.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package adyen

import (
"github.com/BoltApp/sleet"
"time"

"github.com/BoltApp/sleet"
)

const (
Expand Down
7 changes: 5 additions & 2 deletions gateways/adyen/rtau_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
//go:build unit
// +build unit

package adyen

import (
"github.com/BoltApp/sleet"
"github.com/go-test/deep"
"testing"
"time"

"github.com/go-test/deep"

"github.com/BoltApp/sleet"
)

func TestGetRTAUStatus(t *testing.T) {
Expand Down
10 changes: 6 additions & 4 deletions gateways/authorizenet/authorizenet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ package authorizenet

import (
"fmt"
"net/http"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/jarcoal/httpmock"

"github.com/BoltApp/sleet"
"github.com/BoltApp/sleet/common"
sleet_t "github.com/BoltApp/sleet/testing"
"github.com/google/go-cmp/cmp"
"github.com/jarcoal/httpmock"
"net/http"
"testing"
)

func TestNewClient(t *testing.T) {
Expand Down
8 changes: 5 additions & 3 deletions gateways/authorizenet/request_builders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ package authorizenet

import (
"encoding/json"
"testing"

"github.com/Pallinder/go-randomdata"
"github.com/go-test/deep"

"github.com/BoltApp/sleet"
"github.com/BoltApp/sleet/common"
sleet_testing "github.com/BoltApp/sleet/testing"
"github.com/Pallinder/go-randomdata"
"github.com/go-test/deep"
"testing"
)

func TestBuildAuthRequest(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions gateways/authorizenet/translation_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build unit
// +build unit

package authorizenet
Expand Down
1 change: 1 addition & 0 deletions gateways/braintree/braintree.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

braintree_go "github.com/BoltApp/braintree-go"

"github.com/BoltApp/sleet"
"github.com/BoltApp/sleet/common"
)
Expand Down
1 change: 1 addition & 0 deletions gateways/braintree/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package braintree

import (
"github.com/BoltApp/braintree-go"

"github.com/BoltApp/sleet/common"
)

Expand Down
2 changes: 2 additions & 0 deletions gateways/braintree/request_builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package braintree

import (
"fmt"

braintree_go "github.com/BoltApp/braintree-go"

"github.com/BoltApp/sleet"
"github.com/BoltApp/sleet/common"
)
Expand Down
3 changes: 2 additions & 1 deletion gateways/cardconnect/request_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (

"github.com/BoltApp/sleet"

sleet_testing "github.com/BoltApp/sleet/testing"
"github.com/go-test/deep"

sleet_testing "github.com/BoltApp/sleet/testing"
)

var (
Expand Down
10 changes: 6 additions & 4 deletions gateways/checkoutcom/checkoutcom.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package checkoutcom

import (
"github.com/BoltApp/sleet"
"github.com/BoltApp/sleet/common"
"github.com/checkout/checkout-sdk-go"
"github.com/checkout/checkout-sdk-go/payments"
"net/http"
"strconv"

"github.com/checkout/checkout-sdk-go"
"github.com/checkout/checkout-sdk-go/payments"

"github.com/BoltApp/sleet"
"github.com/BoltApp/sleet/common"
)

// checkout.com documentation here: https://www.checkout.com/docs/four/payments/accept-payments, SDK here: https://github.com/checkout/checkout-sdk-go
Expand Down
7 changes: 5 additions & 2 deletions gateways/checkoutcom/environment.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package checkoutcom

import "github.com/BoltApp/sleet/common"
import "github.com/checkout/checkout-sdk-go"
import (
"github.com/checkout/checkout-sdk-go"

"github.com/BoltApp/sleet/common"
)

func GetEnv(env common.Environment) checkout.SupportedEnvironment {
if env == common.Production {
Expand Down
Loading

0 comments on commit 2f475fe

Please sign in to comment.