Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aknysh committed Mar 10, 2025
1 parent bb7e0e9 commit ea8edbb
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/utils/markdown_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ import (
"os/exec"
"runtime/debug"

l "github.com/charmbracelet/log"
log "github.com/charmbracelet/log"
"golang.org/x/text/cases"
"golang.org/x/text/language"

"github.com/cloudposse/atmos/pkg/schema"
"github.com/cloudposse/atmos/pkg/ui/markdown"
)

// render is the global markdown renderer instance initialized via InitializeMarkdown
// render is the global markdown renderer instance initialized via InitializeMarkdown.
var render *markdown.Renderer

// PrintErrorMarkdown prints an error message in Markdown format.
func PrintErrorMarkdown(title string, err error, suggestion string) {
if err == nil {
return
Expand All @@ -43,12 +44,12 @@ func PrintErrorMarkdown(title string, err error, suggestion string) {
LogError(err)
}
// Print stack trace
if l.GetLevel() == l.DebugLevel {
if log.GetLevel() == log.DebugLevel {

Check warning on line 47 in pkg/utils/markdown_utils.go

View check run for this annotation

Codecov / codecov/patch

pkg/utils/markdown_utils.go#L47

Added line #L47 was not covered by tests
debug.PrintStack()
}
}

// PrintfErrorMarkdown prints a formatted error message in markdown format
// PrintfErrorMarkdown prints a formatted error message in Markdown format.
func PrintfErrorMarkdown(format string, a ...interface{}) {
if render == nil {
LogError(fmt.Errorf(format, a...))

Check failure on line 55 in pkg/utils/markdown_utils.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] pkg/utils/markdown_utils.go#L55

do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(format, a...)" (err113)
Raw output
pkg/utils/markdown_utils.go:55:12: do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf(format, a...)" (err113)
		LogError(fmt.Errorf(format, a...))
		         ^
Expand All @@ -66,6 +67,7 @@ func PrintfErrorMarkdown(format string, a ...interface{}) {
LogError(err)
}

// PrintErrorMarkdownAndExit prints an error message in Markdown format and exist with the exit code 1.
func PrintErrorMarkdownAndExit(title string, err error, suggestion string) {
PrintErrorMarkdown(title, err, suggestion)

Expand All @@ -78,10 +80,12 @@ func PrintErrorMarkdownAndExit(title string, err error, suggestion string) {
os.Exit(1)

Check failure on line 80 in pkg/utils/markdown_utils.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] pkg/utils/markdown_utils.go#L80

deep-exit: calls to os.Exit only in main() or init() functions (revive)
Raw output
pkg/utils/markdown_utils.go:80:2: deep-exit: calls to os.Exit only in main() or init() functions (revive)
	os.Exit(1)
	^
}

// PrintInvalidUsageErrorAndExit prints a message about the incorrect command usage and exist with the exit code 1.
func PrintInvalidUsageErrorAndExit(err error, suggestion string) {
PrintErrorMarkdownAndExit("Incorrect Usage", err, suggestion)
}

// PrintfMarkdown prints a message in Markdown format.
func PrintfMarkdown(format string, a ...interface{}) {
if render == nil {
_, err := os.Stdout.WriteString(fmt.Sprintf(format, a...))
Expand All @@ -99,6 +103,7 @@ func PrintfMarkdown(format string, a ...interface{}) {
LogError(err)
}

// InitializeMarkdown initializes a new Markdown renderer.
func InitializeMarkdown(atmosConfig schema.AtmosConfiguration) {

Check failure on line 107 in pkg/utils/markdown_utils.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] pkg/utils/markdown_utils.go#L107

hugeParam: atmosConfig is heavy (5760 bytes); consider passing it by pointer (gocritic)
Raw output
pkg/utils/markdown_utils.go:107:25: hugeParam: atmosConfig is heavy (5760 bytes); consider passing it by pointer (gocritic)
func InitializeMarkdown(atmosConfig schema.AtmosConfiguration) {
                        ^
var err error
render, err = markdown.NewTerminalMarkdownRenderer(atmosConfig)
Expand Down

0 comments on commit ea8edbb

Please sign in to comment.