Skip to content

Commit

Permalink
Go build workflow coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Cataldo committed Dec 5, 2023
1 parent 8d0e5d4 commit 2db1b38
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 43 deletions.
27 changes: 16 additions & 11 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ on:

jobs:
build:

runs-on: self-hosted
steps:
- uses: actions/checkout@v4
Expand All @@ -21,13 +20,19 @@ jobs:
run: go version
- name: Install dependencies
run: |
go get .
go get github.com/mattn/goveralls
- name: Build
run: go build -v ./...
# - name: Import Goveralls
# run: go get github.com/mattn/goveralls
# - name: Test Covarage
# run: go test -v -covermode=count -coverprofile=coverage.out ./asaas/...
# - name: Export Covarage
# run: $GOPATH/goveralls -coverprofile=coverage.out -service=travis-ci -repotoken=$COVERALLS_TOKEN
go mod download
- name: Run Unit tests
env:
ASAAS_ACCESS_TOKEN: ${{ secrets.ASAAS_ACCESS_TOKEN }}
ASAAS_ACCESS_TOKEN_SECONDARY: ${{ secrets.ASAAS_ACCESS_TOKEN_SECONDARY }}
ASAAS_WALLET_ID: ${{ secrets.ASAAS_WALLET_ID }}
ASAAS_WALLET_ID_SECONDARY: ${{ secrets.ASAAS_WALLET_ID_SECONDARY }}
COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
run: |
go test -race -covermode atomic -coverprofile=covprofile ./asaas/...
- name: Install goveralls
run: go install github.com/mattn/goveralls@latest
- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
run: goveralls -coverprofile=covprofile -service=github
2 changes: 1 addition & 1 deletion asaas/charge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestChargeReceiveInCashById(t *testing.T) {
now := DateNow()
resp, err := nCharge.ReceiveInCashById(ctx, chargeId, ChargeReceiveInCashRequest{
PaymentDate: NewDate(now.Year(), now.Month(), now.Day(), now.Location()),
Value: 100,
Value: 5,
NotifyCustomer: false,
})
assertResponseSuccess(t, resp, err)
Expand Down
2 changes: 1 addition & 1 deletion asaas/invoice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestInvoiceSchedule(t *testing.T) {
ServiceDescription: "Unit test go",
Observations: "Unit test go",
ExternalReference: "",
Value: 100,
Value: 5,
Deductions: 0,
EffectiveDate: Date{},
MunicipalServiceId: "",
Expand Down
35 changes: 9 additions & 26 deletions asaas/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func TestMain(m *testing.M) {
code := m.Run()
logInfo(EnvSandbox, "cleaning all envs")
clearCustomerId()
clearCreditCardChargeId()
clearPixChargeId()
clearUndefinedChargeId()
clearBillPaymentId()
Expand Down Expand Up @@ -138,7 +137,6 @@ func initCustomerDeleted() {

func initCreditCardCharge(withInstallment bool) {
initCustomer()
clearCreditCardChargeId()
accessToken := getEnvValue(EnvAccessToken)
customerId := getEnvValue(EnvCustomerId)
ctx, cancel := context.WithTimeout(context.TODO(), 40*time.Second)
Expand All @@ -147,7 +145,7 @@ func initCreditCardCharge(withInstallment bool) {
req := CreateChargeRequest{
Customer: customerId,
BillingType: BillingTypeCreditCard,
Value: 100,
Value: 500,
DueDate: NewDate(now.Year(), now.Month(), now.Day(), now.Location()),
Description: "Cobrança via teste unitário em Golang",
CreditCard: &CreditCardRequest{
Expand Down Expand Up @@ -196,7 +194,7 @@ func initPixCharge() {
Customer: customerId,
BillingType: BillingTypePix,
DueDate: NewDate(now.Year(), now.Month(), now.Day(), now.Location()),
Value: 100,
Value: 5,
Description: "Cobrança via teste unitário em Golang",
})
if err != nil || resp.IsNoContent() || resp.IsFailure() {
Expand Down Expand Up @@ -224,7 +222,7 @@ func initBankSlipCharge(withInstallment bool) {
Customer: customerId,
BillingType: BillingTypeBankSlip,
DueDate: NewDate(now.Year(), now.Month(), now.Day(), now.Location()),
Value: 100,
Value: 5,
Description: "Cobrança via teste unitário em Golang",
}
if withInstallment {
Expand Down Expand Up @@ -259,7 +257,7 @@ func initUndefinedCharge() {
resp, err := chargeAsaas.Create(ctx, CreateChargeRequest{
Customer: customerId,
BillingType: BillingTypeUndefined,
Value: 100,
Value: 5,
DueDate: NewDate(now.Year(), now.Month(), now.Day(), now.Location()),
Description: "Cobrança via teste unitário em Golang",
})
Expand Down Expand Up @@ -295,7 +293,7 @@ func initChargeReceivedInCash() {
chargeAsaas := NewCharge(EnvSandbox, accessToken)
resp, err := chargeAsaas.ReceiveInCashById(ctx, chargeId, ChargeReceiveInCashRequest{
PaymentDate: NewDate(now.Year(), now.Month(), now.Day(), now.Location()),
Value: 100,
Value: 5,
})
if err != nil || resp.IsNoContent() || resp.IsFailure() {
logError("error resp:", resp, "err: ", err)
Expand Down Expand Up @@ -440,7 +438,7 @@ func initInvoice() {
ServiceDescription: "Unit test go",
Observations: "Unit test go",
ExternalReference: "",
Value: 100,
Value: 5,
Deductions: 0,
EffectiveDate: Date{},
MunicipalServiceId: "",
Expand Down Expand Up @@ -594,7 +592,7 @@ func initPixTransaction() {
Payload: pixQrCodePayload,
ChangeValue: 0,
},
Value: 100,
Value: 5,
Description: "",
ScheduleDate: Date{},
})
Expand Down Expand Up @@ -726,7 +724,7 @@ func initSubscription() {
resp, err := nSubscription.Create(ctx, CreateSubscriptionRequest{
Customer: customerId,
BillingType: BillingTypeBankSlip,
Value: 100,
Value: 5,
NextDueDate: NewDate(now.Year(), now.Month()+1, now.Day(), now.Location()),
Cycle: SubscriptionCycleMonthly,
Description: "Unit test go",
Expand Down Expand Up @@ -769,26 +767,11 @@ func clearCustomerId() {
_ = os.Unsetenv(EnvCustomerId)
}

func clearCreditCardChargeId() {
accessToken := getEnvValueWithoutLogger(EnvAccessToken)
ctx, cancel := context.WithTimeout(context.TODO(), 40*time.Second)
defer cancel()
chargeId := getEnvValueWithoutLogger(EnvCreditCardChargeId)
if util.IsBlank(&chargeId) {
return
}
chargeAsaas := NewCharge(EnvSandbox, accessToken)
_, _ = chargeAsaas.RefundById(ctx, chargeId, RefundRequest{
Description: "unit test golang",
})
_ = os.Unsetenv(EnvCreditCardChargeId)
}

func clearPixChargeId() {
accessToken := getEnvValueWithoutLogger(EnvAccessToken)
ctx, cancel := context.WithTimeout(context.TODO(), 40*time.Second)
defer cancel()
chargeId := getEnvValueWithoutLogger(EnvCreditCardChargeId)
chargeId := getEnvValueWithoutLogger(EnvPixChargeId)
if util.IsBlank(&chargeId) {
return
}
Expand Down
2 changes: 1 addition & 1 deletion asaas/pix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestPixPayQrCode(t *testing.T) {
Payload: pixQrCodePayload,
ChangeValue: 0,
},
Value: 100,
Value: 5,
Description: "",
ScheduleDate: Date{},
})
Expand Down
5 changes: 3 additions & 2 deletions asaas/subaccount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package asaas
import (
"context"
"github.com/GabrielHCataldo/go-asaas/internal/util"
"github.com/mvrilo/go-cpf"
"os"
"testing"
"time"
Expand All @@ -17,9 +18,9 @@ func TestSubaccountCreate(t *testing.T) {
Name: "Unit test go",
Email: util.GenerateEmail(),
LoginEmail: "",
CpfCnpj: "81452811000125",
CpfCnpj: cpf.Generate(),
BirthDate: NewDate(1999, 6, 12, time.Local),
CompanyType: CompanyTypeLimited,
CompanyType: "",
Phone: "",
MobilePhone: util.GenerateMobilePhone(),
Site: "",
Expand Down
2 changes: 1 addition & 1 deletion asaas/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestSubscriptionCreate(t *testing.T) {
resp, err := nSubscription.Create(ctx, CreateSubscriptionRequest{
Customer: customerId,
BillingType: BillingTypeBankSlip,
Value: 100,
Value: 5,
NextDueDate: NewDate(now.Year(), now.Month()+1, now.Day(), now.Location()),
Discount: nil,
Interest: nil,
Expand Down

0 comments on commit 2db1b38

Please sign in to comment.