From 2db1b3840ed60d41345e2c2e85d163f9b0e2b8da Mon Sep 17 00:00:00 2001 From: Gabriel Cataldo Date: Tue, 5 Dec 2023 17:39:13 -0300 Subject: [PATCH] Go build workflow coverage --- .github/workflows/go.yml | 27 ++++++++++++++++----------- asaas/charge_test.go | 2 +- asaas/invoice_test.go | 2 +- asaas/main_test.go | 35 +++++++++-------------------------- asaas/pix_test.go | 2 +- asaas/subaccount_test.go | 5 +++-- asaas/subscription_test.go | 2 +- 7 files changed, 32 insertions(+), 43 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 90bdc39..9a28dd9 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -9,7 +9,6 @@ on: jobs: build: - runs-on: self-hosted steps: - uses: actions/checkout@v4 @@ -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 diff --git a/asaas/charge_test.go b/asaas/charge_test.go index 3008ca8..75cf01c 100644 --- a/asaas/charge_test.go +++ b/asaas/charge_test.go @@ -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) diff --git a/asaas/invoice_test.go b/asaas/invoice_test.go index f34d4d0..ab0637f 100644 --- a/asaas/invoice_test.go +++ b/asaas/invoice_test.go @@ -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: "", diff --git a/asaas/main_test.go b/asaas/main_test.go index 2796482..1dc2cf8 100644 --- a/asaas/main_test.go +++ b/asaas/main_test.go @@ -58,7 +58,6 @@ func TestMain(m *testing.M) { code := m.Run() logInfo(EnvSandbox, "cleaning all envs") clearCustomerId() - clearCreditCardChargeId() clearPixChargeId() clearUndefinedChargeId() clearBillPaymentId() @@ -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) @@ -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{ @@ -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() { @@ -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 { @@ -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", }) @@ -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) @@ -440,7 +438,7 @@ func initInvoice() { ServiceDescription: "Unit test go", Observations: "Unit test go", ExternalReference: "", - Value: 100, + Value: 5, Deductions: 0, EffectiveDate: Date{}, MunicipalServiceId: "", @@ -594,7 +592,7 @@ func initPixTransaction() { Payload: pixQrCodePayload, ChangeValue: 0, }, - Value: 100, + Value: 5, Description: "", ScheduleDate: Date{}, }) @@ -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", @@ -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 } diff --git a/asaas/pix_test.go b/asaas/pix_test.go index bc2cbe8..2f63607 100644 --- a/asaas/pix_test.go +++ b/asaas/pix_test.go @@ -18,7 +18,7 @@ func TestPixPayQrCode(t *testing.T) { Payload: pixQrCodePayload, ChangeValue: 0, }, - Value: 100, + Value: 5, Description: "", ScheduleDate: Date{}, }) diff --git a/asaas/subaccount_test.go b/asaas/subaccount_test.go index da15aed..4263f13 100644 --- a/asaas/subaccount_test.go +++ b/asaas/subaccount_test.go @@ -3,6 +3,7 @@ package asaas import ( "context" "github.com/GabrielHCataldo/go-asaas/internal/util" + "github.com/mvrilo/go-cpf" "os" "testing" "time" @@ -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: "", diff --git a/asaas/subscription_test.go b/asaas/subscription_test.go index 89bfa57..da2b7f4 100644 --- a/asaas/subscription_test.go +++ b/asaas/subscription_test.go @@ -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,