зеркало из https://github.com/microsoft/abstrakt.git
Fixed liniting issues.
This commit is contained in:
Родитель
15ab9aec14
Коммит
2ad0948263
|
@ -52,7 +52,7 @@ func DefaultRootCommand() *cobra.Command {
|
|||
return nil
|
||||
}
|
||||
|
||||
addCommands(c, newComposeCmd(), newVersionCmd(), newVisualiseCmd(), newValidateCmd(), newDiffCmd())
|
||||
addCommands(c, newComposeCmd(), newVersionCmd(), newVisualizeCmd(), newValidateCmd(), newDiffCmd())
|
||||
|
||||
return c
|
||||
}
|
||||
|
|
10
cmd/diff.go
10
cmd/diff.go
|
@ -1,9 +1,9 @@
|
|||
package cmd
|
||||
|
||||
// visualise is a subcommand that constructs a graph representation of the yaml
|
||||
// visualize is a subcommand that constructs a graph representation of the yaml
|
||||
// input file and renders this into GraphViz 'dot' notation.
|
||||
// Initial version renders to dot syntax only, to graphically depict this the output
|
||||
// has to be run through a graphviz visualisation tool/utiliyy
|
||||
// has to be run through a graphviz visualization tool/utiliyy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
@ -57,7 +57,8 @@ Example: abstrakt diff -o [constellationFilePathOriginal] -n [constellationFileP
|
|||
|
||||
if *cc.showOriginal {
|
||||
out := &bytes.Buffer{}
|
||||
resStringOrg, err := dsGraphOrg.GenerateGraph(out)
|
||||
var resStringOrg string
|
||||
resStringOrg, err = dsGraphOrg.GenerateGraph(out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -72,7 +73,8 @@ Example: abstrakt diff -o [constellationFilePathOriginal] -n [constellationFileP
|
|||
|
||||
if *cc.showNew {
|
||||
out := &bytes.Buffer{}
|
||||
resStringNew, err := dsGraphNew.GenerateGraph(out)
|
||||
var resStringNew string
|
||||
resStringNew, err = dsGraphNew.GenerateGraph(out)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ Example: abstrakt validate -f [constellationFilePath] -m [mapperFilePath]
|
|||
|
||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
if len(cc.constellationFilePath) == 0 && len(cc.mapperFilePath) == 0 {
|
||||
cc.baseCmd.cmd.Usage()
|
||||
_ = cc.baseCmd.cmd.Usage()
|
||||
return fmt.Errorf("no flags were set")
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package cmd
|
||||
|
||||
// visualise is a subcommand that constructs a graph representation of the yaml
|
||||
// visualize is a subcommand that constructs a graph representation of the yaml
|
||||
// input file and renders this into GraphViz 'dot' notation.
|
||||
// Initial version renders to dot syntax only, to graphically depict this the output
|
||||
// has to be run through a graphviz visualisation tool/utiliyy
|
||||
// has to be run through a graphviz visualization tool/utiliyy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
@ -15,20 +15,20 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
type visualiseCmd struct {
|
||||
type visualizeCmd struct {
|
||||
constellationFilePath string
|
||||
*baseCmd
|
||||
}
|
||||
|
||||
func newVisualiseCmd() *visualiseCmd {
|
||||
cc := &visualiseCmd{}
|
||||
func newVisualizeCmd() *visualizeCmd {
|
||||
cc := &visualizeCmd{}
|
||||
|
||||
cc.baseCmd = newBaseCmd(&cobra.Command{
|
||||
Use: "visualise",
|
||||
Use: "visualize",
|
||||
Short: "Format a constellation configuration as Graphviz dot notation",
|
||||
Long: `Visualise is for producing Graphviz dot notation code of a constellation configuration
|
||||
Long: `Visualize is for producing Graphviz dot notation code of a constellation configuration
|
||||
|
||||
Example: abstrakt visualise -f [constellationFilePath]`,
|
||||
Example: abstrakt visualize -f [constellationFilePath]`,
|
||||
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
logger.Debug("args: " + strings.Join(args, " "))
|
|
@ -11,11 +11,11 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestVisualiseCmdWithAllRequirementsNoError(t *testing.T) {
|
||||
func TestVisualizeCmdWithAllRequirementsNoError(t *testing.T) {
|
||||
constellationPath := "testdata/constellation/valid.yaml"
|
||||
|
||||
hook := test.NewGlobal()
|
||||
_, err := helpers.ExecuteCommand(newVisualiseCmd().cmd, "-f", constellationPath)
|
||||
_, err := helpers.ExecuteCommand(newVisualizeCmd().cmd, "-f", constellationPath)
|
||||
|
||||
if err != nil {
|
||||
t.Error("Did not receive output")
|
||||
|
@ -24,10 +24,10 @@ func TestVisualiseCmdWithAllRequirementsNoError(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestVisualiseCmdFailYaml(t *testing.T) {
|
||||
func TestVisualizeCmdFailYaml(t *testing.T) {
|
||||
expected := "Could not open YAML input file for reading"
|
||||
|
||||
output, err := helpers.ExecuteCommand(newVisualiseCmd().cmd, "-f", "constellationPath")
|
||||
output, err := helpers.ExecuteCommand(newVisualizeCmd().cmd, "-f", "constellationPath")
|
||||
|
||||
if err != nil {
|
||||
assert.Contains(t, err.Error(), expected)
|
||||
|
@ -36,10 +36,10 @@ func TestVisualiseCmdFailYaml(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestVisualiseCmdFailNotYaml(t *testing.T) {
|
||||
func TestVisualizeCmdFailNotYaml(t *testing.T) {
|
||||
expected := "dagConfigService failed to load file"
|
||||
|
||||
output, err := helpers.ExecuteCommand(newVisualiseCmd().cmd, "-f", "visualise.go")
|
||||
output, err := helpers.ExecuteCommand(newVisualizeCmd().cmd, "-f", "visualize.go")
|
||||
|
||||
if err != nil {
|
||||
assert.Contains(t, err.Error(), expected)
|
||||
|
@ -49,13 +49,12 @@ func TestVisualiseCmdFailNotYaml(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFileExists(t *testing.T) {
|
||||
|
||||
_, _, tdir := helpers.PrepareRealFilesForTest(t)
|
||||
|
||||
defer helpers.CleanTempTestFiles(t, tdir)
|
||||
|
||||
//Setup variables and content for test
|
||||
testValidFilename := filepath.Join(tdir, "testVisualise.out")
|
||||
testValidFilename := filepath.Join(tdir, "testVisualize.out")
|
||||
testInvalidFilename := filepath.Join(tdir, "nonexistant.out")
|
||||
testData := []byte("A file to test with")
|
||||
|
|
@ -15,7 +15,7 @@ Available Commands:
|
|||
help Help about any command
|
||||
validate Validate a constellation file for correct schema and ensure correctness.
|
||||
version The version of Abstrakt being used
|
||||
visualise Format a constellation configuration as Graphviz dot notation
|
||||
visualize Format a constellation configuration as Graphviz dot notation
|
||||
|
||||
Flags:
|
||||
-h, --help help for abstrakt
|
||||
|
@ -80,27 +80,27 @@ Global Flags:
|
|||
-v, --verbose Use verbose output logs
|
||||
```
|
||||
|
||||
### abstrakt `visualise`
|
||||
### abstrakt `visualize`
|
||||
|
||||
```bash
|
||||
Visualise is for producing Graphviz dot notation code of a constellation configuration
|
||||
Visualize is for producing Graphviz dot notation code of a constellation configuration
|
||||
|
||||
Example: abstrakt visualise -f [constellationFilePath]
|
||||
Example: abstrakt visualize -f [constellationFilePath]
|
||||
|
||||
Usage:
|
||||
abstrakt visualise [flags]
|
||||
abstrakt visualize [flags]
|
||||
|
||||
Flags:
|
||||
-f, --constellationFilePath string constellation file path
|
||||
-h, --help help for visualise
|
||||
-h, --help help for visualize
|
||||
|
||||
Global Flags:
|
||||
-v, --verbose Use verbose output logs
|
||||
```
|
||||
|
||||
The output from the visualise subcommand is [Graphviz dot notation](https://www.graphviz.org/doc/info/lang.html)
|
||||
The output from the visualize subcommand is [Graphviz dot notation](https://www.graphviz.org/doc/info/lang.html)
|
||||
|
||||
The output from a call to 'abstrakt visualise' can be piped into Graphviz to generate a graphical output. See the example in the Examples section.
|
||||
The output from a call to 'abstrakt visualize' can be piped into Graphviz to generate a graphical output. See the example in the Examples section.
|
||||
|
||||
Alternatively, copy the output and paste into a Graphviz rendering tool to see the graph produced. Some sites listed below (rendering option in the utility to be developed).
|
||||
|
||||
|
@ -129,9 +129,9 @@ Global Flags:
|
|||
|
||||
#### Examples
|
||||
|
||||
Run visualise on a file
|
||||
Run visualize on a file
|
||||
|
||||
abstrakt visualise -f basic_azure_event_hubs.yaml
|
||||
abstrakt visualize -f basic_azure_event_hubs.yaml
|
||||
digraph Azure_Event_Hubs_Sample {
|
||||
Event_Generator->Azure_Event_Hub;
|
||||
Azure_Event_Hub->Event_Logger;
|
||||
|
@ -141,6 +141,6 @@ Run visualise on a file
|
|||
|
||||
}
|
||||
|
||||
Pipe visualise output to Graphviz producing a file called result.png (assumes Graphviz is installed and can be called from the location abstrakt is being run)
|
||||
Pipe visualize output to Graphviz producing a file called result.png (assumes Graphviz is installed and can be called from the location abstrakt is being run)
|
||||
|
||||
abstrakt visualise -f ./examples/constellation/sample_consteallation.yaml | dot -Tpng > result.png
|
||||
abstrakt visualize -f ./examples/constellation/sample_consteallation.yaml | dot -Tpng > result.png
|
|
@ -17,7 +17,7 @@ type Composer struct {
|
|||
//Build takes the loaded DAG and maps and builds the Helm values and requirements documents
|
||||
func (m *Composer) Build(name string, dir string) (*helm.Chart, error) {
|
||||
if m.Constellation.Name == "" || m.Mapper.Name == "" {
|
||||
return nil, fmt.Errorf("Please initialise with LoadFromFile or LoadFromString")
|
||||
return nil, fmt.Errorf("Please initialize with LoadFromFile or LoadFromString")
|
||||
}
|
||||
|
||||
newChart, err := chart.Create(name, dir)
|
||||
|
|
|
@ -67,10 +67,10 @@ func createSet(dsGraph *Config) (set.Set, set.Set) {
|
|||
}
|
||||
|
||||
// CreateGraphWithChanges - use both input constellations (new and original) as well as the comparison sets to create
|
||||
// a dag that can be visualised. It uses the comparison sets to identify additions, deletions and changes between the original
|
||||
// a dag that can be visualized. It uses the comparison sets to identify additions, deletions and changes between the original
|
||||
// and new constellations.
|
||||
func CreateGraphWithChanges(newGraph *Config, sets *ComparisonSet) (string, error) {
|
||||
// Lookup is used to map IDs to names. Names are easier to visualise but IDs are more important to ensure the
|
||||
// Lookup is used to map IDs to names. Names are easier to visualize but IDs are more important to ensure the
|
||||
// presented constellation is correct and IDs are used to link nodes together
|
||||
lookup := make(map[string]string)
|
||||
g := gographviz.NewGraph()
|
||||
|
@ -90,7 +90,7 @@ func CreateGraphWithChanges(newGraph *Config, sets *ComparisonSet) (string, erro
|
|||
}
|
||||
|
||||
// Add all services from the new constellation
|
||||
// - New services - highlight with colour (i.e in setAddedSvcs)
|
||||
// - New services - highlight with color (i.e in setAddedSvcs)
|
||||
// - Deleted services (i.e. in setDelSvcs) - include and format appropriately
|
||||
for _, v := range newGraph.Services {
|
||||
newName := strings.Replace(v.ID, " ", "_", -1) // Replace spaces in names with underscores, names with spaces can break graphviz engines)
|
||||
|
@ -128,7 +128,7 @@ func CreateGraphWithChanges(newGraph *Config, sets *ComparisonSet) (string, erro
|
|||
|
||||
//======================================== process relationships ==========================================
|
||||
// Add Relationships from the new constellation
|
||||
// - New relationships - highlight with colour (i.e. in setAddedSvcs)
|
||||
// - New relationships - highlight with color (i.e. in setAddedSvcs)
|
||||
// - Deleted relationships (i.e. in setDelRels) - include and format appropriately
|
||||
for _, v := range newGraph.Relationships {
|
||||
//Surround names/labels with quotes, stops graphviz seeing special characters and breaking
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
// this can be passed on to GraphViz to graphically render the resulting graph
|
||||
func (readGraph *Config) GenerateGraph(out io.Writer) (string, error) {
|
||||
|
||||
// Lookup is used to map IDs to names. Names are easier to visualise but IDs are more important to ensure the
|
||||
// Lookup is used to map IDs to names. Names are easier to visualize but IDs are more important to ensure the
|
||||
// presented constellation is correct and IDs are used to link nodes together
|
||||
lookup := make(map[string]string)
|
||||
|
||||
|
|
4
makefile
4
makefile
|
@ -99,8 +99,8 @@ fmt:
|
|||
build:
|
||||
go build -o abstrakt main.go
|
||||
|
||||
visualise: build
|
||||
./abstrakt visualise -f ./examples/constellation/http_constellation.yaml | dot -Tpng > result.png
|
||||
visualize: build
|
||||
./abstrakt visualize -f ./examples/constellation/http_constellation.yaml | dot -Tpng > result.png
|
||||
|
||||
diff: build
|
||||
./abstrakt diff -o ./examples/constellation/sample_constellation.yaml -n ./examples/constellation/sample_constellation_changed.yaml | dot -Tpng > result.png
|
||||
|
|
Загрузка…
Ссылка в новой задаче