Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverage test binary #17

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
73 changes: 73 additions & 0 deletions cmd/covertest/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package covertest

//go:generate go test -c -o=../../bin/covertest

import (
"errors"
"fmt"
"testing"

"github.com/eltorocorp/drygopher/drygopher/coverage"
"github.com/eltorocorp/drygopher/drygopher/coverage/analysis"
"github.com/eltorocorp/drygopher/drygopher/coverage/analysis/raw"
"github.com/eltorocorp/drygopher/drygopher/coverage/coverageerrors"
"github.com/eltorocorp/drygopher/drygopher/coverage/host"
"github.com/eltorocorp/drygopher/drygopher/coverage/packages"
"github.com/eltorocorp/drygopher/drygopher/coverage/profile"
"github.com/eltorocorp/drygopher/drygopher/coverage/report"
"github.com/stretchr/testify/assert"
)

func TestCoverage40(t *testing.T) {
assert.NoError(t, requireCoverage(40))
}

func TestCoverage55(t *testing.T) {
assert.NoError(t, requireCoverage(55))
}

func TestCoverage70(t *testing.T) {
assert.NoError(t, requireCoverage(70))
}

func TestCoverage80(t *testing.T) {
assert.NoError(t, requireCoverage(80))
}

func requireCoverage(coverage float64) error {
err := checkCoveragePercentage(coverage)
if err == nil {
return nil
}

var coverErr coverageerrors.CoverageBelowStandard
if errors.As(err, &coverErr) {
return fmt.Errorf("Покрытие тестами ниже требуемого: %w", err)
}

var unitErr coverageerrors.UnitTestFailed
if errors.As(err, &unitErr) {
return errors.New("Один или несколько юнит-тестов завершились с ошибкой. Проверьте успешность прохождения тестов с флагом `-race`")
}

return fmt.Errorf("Невозможно определить степень покрытия кода тестами: %w", err)
}

func checkCoveragePercentage(coverageStandard float64) error {
suppressProfile := true
suppressPercentageFile := true
profileName := ""
packageExclusions := []string{"/vendor/", "_test"}

execAPI := new(host.Exec)
osioAPI := new(host.OSIO)
packageAPI := packages.New(execAPI, osioAPI)
profileAPI := profile.New(packageAPI, osioAPI)
reportAPI := report.New(execAPI)
rawAPI := raw.New(osioAPI, execAPI)
analysisAPI := analysis.New(rawAPI)
coverageAPI := coverage.New(packageAPI, analysisAPI, profileAPI, reportAPI)

return coverageAPI.AnalyzeUnitTestCoverage(packageExclusions, coverageStandard, suppressProfile, profileName, suppressPercentageFile)

}
13 changes: 9 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ module github.com/Yandex-Practicum/go-autotests
go 1.16

require (
github.com/go-resty/resty/v2 v2.6.0 // indirect
github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/jackc/pgx v3.6.2+incompatible // indirect
github.com/cockroachdb/apd v1.1.0 // indirect
github.com/eltorocorp/drygopher v1.1.2
github.com/go-resty/resty/v2 v2.6.0
github.com/gofrs/uuid v4.0.0+incompatible
github.com/jackc/fake v0.0.0-20150926172116-812a484cc733 // indirect
github.com/jackc/pgx v3.6.2+incompatible
github.com/jingyugao/rowserrcheck v1.1.0
github.com/lib/pq v1.10.4 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/stretchr/objx v0.3.0 // indirect
github.com/stretchr/testify v1.7.0 // indirect
github.com/stretchr/testify v1.7.0
github.com/timakin/bodyclose v0.0.0-20210704033933-f49887972144
golang.org/x/net v0.0.0-20210716203947-853a461950ff // indirect
golang.org/x/tools v0.1.5
Expand Down
Loading