MCPcopy
hub / github.com/keploy/keploy / SetCoveragePath

Function SetCoveragePath

utils/utils.go:778–817  ·  view source on GitHub ↗

SetCoveragePath takes a goCovPath and sets the coverage path accordingly. It returns an error if the path is a file or if the path does not exist.

(logger *zap.Logger, goCovPath string)

Source from the content-addressed store, hash-verified

776// SetCoveragePath takes a goCovPath and sets the coverage path accordingly.
777// It returns an error if the path is a file or if the path does not exist.
778func SetCoveragePath(logger *zap.Logger, goCovPath string) (string, error) {
779 if goCovPath == "" {
780 // Calculate the current path and create a coverage-reports directory
781 currentPath, err := GetAbsPath("")
782 if err != nil {
783 LogError(logger, err, "failed to get the current working directory")
784 return "", err
785 }
786 goCovPath = currentPath + "/coverage-reports"
787 if err := makeDirectory(goCovPath); err != nil {
788 LogError(logger, err, "failed to create coverage-reports directory", zap.String("CoverageReportPath", goCovPath))
789 return "", err
790 }
791 return goCovPath, nil
792 }
793
794 goCovPath, err := GetAbsPath(goCovPath)
795 if err != nil {
796 LogError(logger, err, "failed to get the absolute path for the coverage report path", zap.String("CoverageReportPath", goCovPath))
797 return "", err
798 }
799 // Check if the path is a directory
800 dirInfo, err := os.Stat(goCovPath)
801 if err != nil {
802 if os.IsNotExist(err) {
803 LogError(logger, err, "the provided path does not exist", zap.String("CoverageReportPath", goCovPath))
804 return "", err
805 }
806 LogError(logger, err, "failed to check the coverage report path", zap.String("CoverageReportPath", goCovPath))
807 return "", err
808 }
809 if !dirInfo.IsDir() {
810 msg := "the coverage report path is not a directory. Please provide a valid path to a directory for go coverage reports"
811
812 LogError(logger, nil, msg, zap.String("CoverageReportPath", goCovPath))
813 return "", errors.New("the path provided is not a directory")
814 }
815
816 return goCovPath, nil
817}
818
819type ErrType string
820

Callers 1

PreProcessMethod · 0.92

Calls 5

GetAbsPathFunction · 0.85
LogErrorFunction · 0.85
makeDirectoryFunction · 0.85
NewMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected