-
Notifications
You must be signed in to change notification settings - Fork 4
/
config_test.go
110 lines (100 loc) · 3.28 KB
/
config_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package kroki
import (
"testing"
"time"
"gopkg.in/yaml.v2"
)
func TestConfiguration(t *testing.T) {
cases := []struct {
in string
want Configuration
}{
{
in: "{}",
want: Configuration{
URL: "https://kroki.io",
Timeout: time.Second * 20,
},
},
{
in: `
url: "https://a.kroki.io"
timeout: 30
`,
want: Configuration{
URL: "https://a.kroki.io",
Timeout: time.Second * 30,
},
},
}
for _, tc := range cases {
var got Configuration
err := yaml.Unmarshal([]byte(tc.in), &got)
if err != nil {
t.Errorf("Unmarshal(%q) error:\n%+v", tc.in, err)
}
if got != tc.want {
t.Errorf("error\ngot:\n%s\nwant:\n%s", got, tc.want)
}
}
}
func TestGetSupportedImageFormats(t *testing.T) {
supportedImageFormats := GetSupportedImageFormats()
checkContainsImageFormat(t, supportedImageFormats, Base64)
checkContainsImageFormat(t, supportedImageFormats, SVG)
checkContainsImageFormat(t, supportedImageFormats, JPEG)
checkContainsImageFormat(t, supportedImageFormats, PDF)
checkContainsImageFormat(t, supportedImageFormats, PNG)
}
func checkContainsImageFormat(t *testing.T, list []ImageFormat, imageFormat ImageFormat) {
if !containsImageFormat(list, imageFormat) {
t.Errorf("error\n%s should be a supported image format", imageFormat)
}
}
func containsImageFormat(s []ImageFormat, imageFormat ImageFormat) bool {
for _, v := range s {
if v == imageFormat {
return true
}
}
return false
}
func TestGetSupportedDiagramTypes(t *testing.T) {
supportedDiagramTypes := GetSupportedDiagramTypes()
checkContainsDiagramType(t, supportedDiagramTypes, ActDiag)
checkContainsDiagramType(t, supportedDiagramTypes, BlockDiag)
checkContainsDiagramType(t, supportedDiagramTypes, BPMN)
checkContainsDiagramType(t, supportedDiagramTypes, Bytefield)
checkContainsDiagramType(t, supportedDiagramTypes, C4PlantUML)
checkContainsDiagramType(t, supportedDiagramTypes, Diagramsnet)
checkContainsDiagramType(t, supportedDiagramTypes, Ditaa)
checkContainsDiagramType(t, supportedDiagramTypes, Erd)
checkContainsDiagramType(t, supportedDiagramTypes, Excalidraw)
checkContainsDiagramType(t, supportedDiagramTypes, Mermaid)
checkContainsDiagramType(t, supportedDiagramTypes, Nomnoml)
checkContainsDiagramType(t, supportedDiagramTypes, NwDiag)
checkContainsDiagramType(t, supportedDiagramTypes, PacketDiag)
checkContainsDiagramType(t, supportedDiagramTypes, Pikchr)
checkContainsDiagramType(t, supportedDiagramTypes, PlantUML)
checkContainsDiagramType(t, supportedDiagramTypes, RackDiag)
checkContainsDiagramType(t, supportedDiagramTypes, SeqDiag)
checkContainsDiagramType(t, supportedDiagramTypes, Structurizr)
checkContainsDiagramType(t, supportedDiagramTypes, Svgbob)
checkContainsDiagramType(t, supportedDiagramTypes, UMlet)
checkContainsDiagramType(t, supportedDiagramTypes, Vega)
checkContainsDiagramType(t, supportedDiagramTypes, VegaLite)
checkContainsDiagramType(t, supportedDiagramTypes, WaveDrom)
}
func checkContainsDiagramType(t *testing.T, list []DiagramType, diagramType DiagramType) {
if !containsDiagramType(list, diagramType) {
t.Errorf("error\n%s should be a supported diagram type", diagramType)
}
}
func containsDiagramType(s []DiagramType, diagramType DiagramType) bool {
for _, v := range s {
if v == diagramType {
return true
}
}
return false
}