/
plantuml.go
68 lines (57 loc) · 1.49 KB
/
plantuml.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
package diagrams
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/alecthomas/assert"
"github.com/anz-bank/sysl/pkg/syslutil"
"github.com/spf13/afero"
"gopkg.in/alecthomas/kingpin.v2"
)
const (
PlantUMLEnvVar = "SYSL_PLANTUML"
PlantUMLDefault = "http://localhost:8080/plantuml"
testDir = "../../tests/"
)
type Plantumlmixin struct {
value string
}
func (p *Plantumlmixin) AddFlag(cmd *kingpin.CmdClause) {
cmd.Flag("plantuml",
"base url of plantuml server (default: "+PlantUMLEnvVar+" or "+
PlantUMLDefault+" see "+
"http://plantuml.com/server.html#install for more info)",
).Short('p').StringVar(&p.value)
}
func (p *Plantumlmixin) Value() string {
if p.value == "" {
p.value = os.Getenv(PlantUMLEnvVar)
if p.value == "" {
p.value = PlantUMLDefault
}
}
return p.value
}
func (p *Plantumlmixin) GenerateFromMap(m map[string]string, fs afero.Fs) error {
for k, v := range m {
if err := OutputPlantuml(k, p.Value(), v, fs); err != nil {
return err
}
}
return nil
}
func ComparePUML(t *testing.T, expected, actual map[string]string) {
for name, goldenFile := range expected {
golden, err := ioutil.ReadFile(goldenFile)
assert.Nil(t, err)
if string(golden) != actual[name] {
err := ioutil.WriteFile(filepath.Join(testDir, name+".puml"), []byte(actual[name]), 0777)
assert.Nil(t, err)
}
golden = syslutil.HandleCRLF(golden)
assert.Equal(t, string(golden), actual[name])
}
// Then
assert.Equal(t, len(expected), len(actual))
}