drawio-export/pkg/drawio/options_internal_test.go
Алексей Бадяев 8d18d7291e
All checks were successful
drawio-export/pipeline/head This commit looks good
Автоматическая сборка пакетов Debian (#4)
This PR closes #2

Reviewed-on: #4
2023-04-12 22:37:54 +07:00

106 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package drawio
import (
"io"
"os"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestOptions(t *testing.T) {
testData := []struct {
name string // Наименование теста
opts []Option // Параметры
app string // Путь к приложению drawio
outdir string // Путь к папке с экспортированными файлами
outext string // Расширение экспортированных файлов
args []string // Аргументы командной строки drawio
}{
{
name: "default",
opts: []Option{},
app: "drawio",
outdir: "export",
outext: ".pdf",
args: []string{},
},
{
name: "svg with all options",
opts: []Option{
WithAppPath("/usr/local/bin/drawio"),
WithOutput("/tmp/images/"),
WithFormat(SVG),
WithRecursive(),
WithRemovePageSuffix(),
WithQuality(100),
WithTransparent(),
WithEmbedDiagram(),
WithEmbedSvgImages(),
WithBorder(1),
WithScale(120),
WithWidth(800),
WithHeight(600),
WithCrop(),
WithUncompressed(),
WithEnablePlugins(),
},
app: "/usr/local/bin/drawio",
outdir: "/tmp/images/",
outext: ".svg",
args: []string{
"--format", "svg",
"--quality", "100",
"--transparent",
"--embed-diagram",
"--embed-svg-images",
"--border", "1",
"--scale", "120",
"--width", "800",
"--height", "600",
"--crop",
"--uncompressed",
"--enable-plugins",
},
},
}
for _, test := range testData {
t.Run(test.name, func(t *testing.T) {
options := Options{}
for _, opt := range test.opts {
opt.apply(&options)
}
assert.Equal(t, test.app, options.App())
assert.Equal(t, test.outdir, options.OutDir())
assert.Equal(t, test.outext, options.OutExt())
assert.ElementsMatch(t, test.args, options.Args())
})
}
}
// Тестовая функция открытия файла
func openFile(name string) (io.ReadCloser, error) {
return nil, nil
}
func TestOptionsOpenFileFunc(t *testing.T) {
opts := New(WithOpenFile(openFile))
assert.Equal(t,
reflect.ValueOf(openFile).Pointer(),
reflect.ValueOf(opts.openFile).Pointer(),
)
}
func readDir(name string) ([]os.DirEntry, error) {
return []os.DirEntry{}, nil
}
func TestOptionsReadDirFunc(t *testing.T) {
opts := New(WithReadDir(readDir))
assert.Equal(t,
reflect.ValueOf(readDir).Pointer(),
reflect.ValueOf(opts.readDir).Pointer(),
)
}