diff --git a/makefile b/makefile index 0b6a4fe..d5023bf 100644 --- a/makefile +++ b/makefile @@ -51,6 +51,7 @@ WHITE := $(shell tput -Txterm setaf 7) CYAN := $(shell tput -Txterm setaf 6) RESET := $(shell tput -Txterm sgr0) +.DEFAULT_GOAL := all .PHONY: all version version-number test build dist vendor package pkg-deb version: ## Version of the project to be built @@ -81,7 +82,7 @@ dist: ## Create all distro packages vendor: ## Copy of all packages needed to support builds and tests in the vendor directory $(GOCMD) mod vendor - @echo "Vendor\t\t${GREEN}[OK]${RESET}" + @$(ECHO_CMD) "Vendor\t\t${GREEN}[OK]${RESET}" clean: ## Remove build related files @rm -fr $(TMPDIR) @@ -145,7 +146,7 @@ ifeq ($(EXPORT_RESULT), true) $(eval OUTPUT_OPTIONS = | go-junit-report -set-exit-code > $(OUTDIR)/junit-report.xml) endif $(GOTEST) -v $(GO_OPT) ./... $(OUTPUT_OPTIONS) - @echo "Test\t\t${GREEN}[OK]${RESET}" + @$(ECHO_CMD) "Test\t\t${GREEN}[OK]${RESET}" coverage: ## Run the tests of the project and export the coverage report. @mkdir -p out @@ -158,11 +159,11 @@ else gocov convert $(OUTDIR)/profile.cov | gocov-xml > $(OUTDIR)/coverage.xml endif endif - @echo "Coverage\t${GREEN}[OK]${RESET}" + @$(ECHO_CMD) "Coverage\t${GREEN}[OK]${RESET}" ## Lint: lint: lint-go ## Run all available linters. - @echo "Lint\t\t${GREEN}[OK]${RESET}" + @$(ECHO_CMD) "Lint\t\t${GREEN}[OK]${RESET}" lint-go: go fmt ./... @@ -170,7 +171,7 @@ lint-go: ## Documentation: doc: doc-golds ## Generate all documents. - @echo "Doc\t\t${GREEN}[OK]${RESET}" + @$(ECHO_CMD) "Doc\t\t${GREEN}[OK]${RESET}" doc-common: @mkdir -p $(DOC_DIR) @@ -182,11 +183,11 @@ doc-golds: doc-common ## Generate HTML documentation with Golds. ## Help: help: ## Show this help. - @echo '' - @echo 'Usage:' - @echo ' ${YELLOW}make${RESET} ${GREEN}${RESET}' - @echo '' - @echo 'Targets:' + @$(ECHO_CMD) '' + @$(ECHO_CMD) 'Usage:' + @$(ECHO_CMD) ' ${YELLOW}make${RESET} ${GREEN}${RESET}' + @$(ECHO_CMD) '' + @$(ECHO_CMD) 'Targets:' @awk 'BEGIN {FS = ":.*?## "} { \ if (/^[a-zA-Z_-]+:.*?##.*$$/) {printf " ${YELLOW}%-20s${GREEN}%s${RESET}\n", $$1, $$2} \ else if (/^## .*$$/) {printf " ${CYAN}%s${RESET}\n", substr($$1,4)} \ diff --git a/pkg/drawio/export_test.go b/pkg/drawio/export_test.go index 8cb4b44..f029260 100644 --- a/pkg/drawio/export_test.go +++ b/pkg/drawio/export_test.go @@ -137,7 +137,7 @@ var testData = []exportTest{ diagrams: []string{"1", "2", "3"}, commands: []command{ { - cmd: "/usr/bin/drawio", + cmd: "drawio", args: []string{ "drawio", "--page-index", "0", "--output", "export/diagrams-1.pdf", @@ -145,7 +145,7 @@ var testData = []exportTest{ }, }, { - cmd: "/usr/bin/drawio", + cmd: "drawio", args: []string{ "drawio", "--page-index", "1", "--output", "export/diagrams-2.pdf", @@ -153,7 +153,7 @@ var testData = []exportTest{ }, }, { - cmd: "/usr/bin/drawio", + cmd: "drawio", args: []string{ "drawio", "--page-index", "2", "--output", "export/diagrams-3.pdf", @@ -222,7 +222,7 @@ var testData = []exportTest{ diagrams: []string{"1", "2", "3"}, commands: []command{ { - cmd: "/usr/bin/drawio", + cmd: "drawio", args: []string{ "drawio", "--page-index", "0", "--output", "export/diagrams-1.pdf", @@ -230,7 +230,7 @@ var testData = []exportTest{ }, }, { - cmd: "/usr/bin/drawio", + cmd: "drawio", args: []string{ "drawio", "--page-index", "1", "--output", "export/diagrams-2.pdf", @@ -238,7 +238,7 @@ var testData = []exportTest{ }, }, { - cmd: "/usr/bin/drawio", + cmd: "drawio", args: []string{ "drawio", "--page-index", "2", "--output", "export/diagrams-3.pdf", @@ -261,7 +261,7 @@ var testData = []exportTest{ diagrams: []string{"Один", "Два"}, commands: []command{ { - cmd: "/usr/bin/drawio", + cmd: "drawio", args: []string{ "drawio", "--page-index", "0", "--output", "export/additional-Один.pdf", @@ -269,7 +269,7 @@ var testData = []exportTest{ }, }, { - cmd: "/usr/bin/drawio", + cmd: "drawio", args: []string{ "drawio", "--page-index", "1", "--output", "export/additional-Два.pdf", @@ -293,7 +293,7 @@ var testData = []exportTest{ diagrams: []string{"Первая диаграмма", "Вторая диаграмма"}, commands: []command{ { - cmd: "/usr/bin/drawio", + cmd: "drawio", args: []string{ "drawio", "--page-index", "0", "--output", "export/subdir/Вложенные диаграммы-Первая диаграмма.pdf", @@ -301,7 +301,7 @@ var testData = []exportTest{ }, }, { - cmd: "/usr/bin/drawio", + cmd: "drawio", args: []string{ "drawio", "--page-index", "1", "--output", "export/subdir/Вложенные диаграммы-Вторая диаграмма.pdf", @@ -314,6 +314,18 @@ var testData = []exportTest{ }, } +// Инициализация тестовых данных +func init() { + for _, test := range testData { + for _, src := range test.files { + for i := range src.commands { + cmd := exec.Command("drawio") + src.commands[i].cmd = cmd.Path + } + } + } +} + func TestDiagrams(t *testing.T) { for _, test := range testData { t.Run(test.name, func(t *testing.T) { diff --git a/pkg/drawio/options.go b/pkg/drawio/options.go index 16ba1ca..6f4b4ca 100644 --- a/pkg/drawio/options.go +++ b/pkg/drawio/options.go @@ -108,11 +108,10 @@ func (opts Options) App() string { if opts.EnableXvfb { return "xvfb-run" } - app := opts.Application - if len(app) == 0 { + if len(opts.Application) == 0 { return "drawio" } - return app + return opts.Application } // Путь к папке с экспортированными файлами @@ -137,8 +136,10 @@ func (opts Options) OutExt() string { func (opts Options) Args() []string { args := []string{} if opts.EnableXvfb { - app := "drawio" - if len(opts.Application) > 0 { + var app string + if len(opts.Application) == 0 { + app = "drawio" + } else { app = opts.Application } args = append(args, "-a", "-l", app)