drawio-export/pkg/drawio/export_test.go
Алексей Бадяев 0d6f42f425
All checks were successful
drawio-export/pipeline/head This commit looks good
Добавлена функция Diagrams() с тестами.
2023-04-08 22:04:55 +07:00

64 lines
1.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_test
import (
"strings"
"testing"
"git.mousesoft.ru/ms/drawio-exporter/pkg/drawio"
"github.com/stretchr/testify/assert"
)
// Тестовые данные
var testData = []struct {
name string // Наименование теста
source string // Данные файла с диаграммами
diagrams []string // Срез имён диаграмм
}{
{
name: "positive case",
source: `<mxfile host="test">
<diagram name="1" id="01">
<mxGraphModel page="1">
</mxGraphModel>
</diagram>
<diagram name="2" id="02">
<mxGraphModel page="1">
</mxGraphModel>
</diagram>
<diagram name="3" id="03">
<mxGraphModel page="1">
</mxGraphModel>
</diagram>
</mxfile>`,
diagrams: []string{"1", "2", "3"},
},
{
name: "invalid source",
source: `<nxfile host="test">
<diagram name="1" id="01">
<mxGraphModel page="1">
</mxGraphModel>
</diagram>
<diagram name="2" id="02">
<mxGraphModel page="1">
</mxGraphModel>
</diagram>
<diagram name="3" id="03">
<mxGraphModel page="1">
</mxGraphModel>
</diagram>
</nxfile>`,
diagrams: []string{},
},
}
func TestDiagrams(t *testing.T) {
for _, test := range testData {
t.Run(test.name, func(t *testing.T) {
diagrams, err := drawio.Diagrams(strings.NewReader(test.source))
assert.NoError(t, err)
assert.ElementsMatch(t, test.diagrams, diagrams)
})
}
}