Исправлен makefile и тесты.
All checks were successful
drawio-export/pipeline/head This commit looks good

This commit is contained in:
Алексей Бадяев 2023-07-02 13:02:04 +07:00
parent 3890a96812
commit e81e76c611
Signed by: alexey
GPG Key ID: 686FBC1363E4AFAE
3 changed files with 39 additions and 25 deletions

View File

@ -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}<target>${RESET}'
@echo ''
@echo 'Targets:'
@$(ECHO_CMD) ''
@$(ECHO_CMD) 'Usage:'
@$(ECHO_CMD) ' ${YELLOW}make${RESET} ${GREEN}<target>${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)} \

View File

@ -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) {

View File

@ -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)