Skip to content

Commit

Permalink
855 grouping legal graph (#908)
Browse files Browse the repository at this point in the history
for graphical representation - add relevant edges to each node so that it is consistent
  • Loading branch information
ShiriMoran authored Oct 10, 2024
1 parent 22fd40b commit c5cdea5
Show file tree
Hide file tree
Showing 22 changed files with 638 additions and 94 deletions.
16 changes: 15 additions & 1 deletion cmd/analyzer/subcmds/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package subcmds
import (
"errors"
"fmt"
"slices"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -79,8 +80,21 @@ func analysisVPCConfigs(cmd *cobra.Command, inArgs *inArgs, analysisType vpcmode
return err
}
outFormat := inArgs.outputFormat.ToModelFormat()
consistencyEdgesExternal := slices.Contains([]vpcmodel.OutFormat{vpcmodel.DRAWIO, vpcmodel.SVG, vpcmodel.HTML},
outFormat)
var groupingType int
switch {
case !inArgs.grouping && !consistencyEdgesExternal:
groupingType = vpcmodel.NoGroupingNoConsistencyEdges
case !inArgs.grouping && consistencyEdgesExternal:
groupingType = vpcmodel.NoGroupingWithConsistencyEdges
case inArgs.grouping && !consistencyEdgesExternal:
groupingType = vpcmodel.GroupingNoConsistencyEdges
default:
groupingType = vpcmodel.GroupingWithConsistencyEdges
}
og, err := vpcmodel.NewOutputGenerator(vpcConfigs,
inArgs.grouping,
groupingType,
analysisType,
false,
inArgs.explanationArgs, outFormat, inArgs.lbAbstraction)
Expand Down
4 changes: 2 additions & 2 deletions pkg/commonvpc/testfunc/analysis_output_test_functionality.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

type VpcAnalysisTest struct {
VpcTestCommon
Grouping bool
GroupingType int
NoLbAbstract bool
}

Expand All @@ -24,6 +24,6 @@ func (tt *VpcAnalysisTest) TestAnalysisSingleTest(t *testing.T, mode testMode, r
tt.setMode(mode)
t.Run(tt.Name, func(t *testing.T) {
t.Parallel()
tt.runSingleCommonTest(t, testDir, rc, tt.Grouping, tt.NoLbAbstract, nil)
tt.runSingleCommonTest(t, testDir, rc, tt.GroupingType, tt.NoLbAbstract, nil)
})
}
27 changes: 20 additions & 7 deletions pkg/commonvpc/testfunc/common_test_functionality.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (
suffixOutFileDiffEndpoints = "endpointsDiff"
suffixOutFileExplain = "explain"
suffixOutFileDetail = "_detail"
consistencyEdgesExternal = "_EdgeConsistent"
txtOutSuffix = ".txt"
mdOutSuffix = ".md"
JSONOutSuffix = ".json"
Expand Down Expand Up @@ -86,6 +87,7 @@ func getTestFileName(testName string,
grouping bool,
noLbAbstract bool,
detailExplain bool,
addConsistencyEdgesExternal bool,
format vpcmodel.OutFormat,
configName string,
allVPCs bool,
Expand Down Expand Up @@ -128,6 +130,9 @@ func getTestFileName(testName string,
if detailExplain {
res += suffixOutFileDetail
}
if addConsistencyEdgesExternal {
res += consistencyEdgesExternal
}
if !allVPCs {
res += strings.ReplaceAll(strings.Join(vpcIDs, ""), ":", "")
}
Expand Down Expand Up @@ -174,9 +179,10 @@ func (tt *VpcTestCommon) initTest() {
}

func (tt *VpcTestCommon) initTestFileNames(uc vpcmodel.OutputUseCase,
vpcName string, allVPCs, detailExplain bool, testDirOut string, grouping, noLbAbstract bool) error {
vpcName string, allVPCs, detailExplain bool, testDirOut string, grouping, noLbAbstract,
addConsistencyEdgesExternal bool) error {
expectedFileName, actualFileName, err := getTestFileName(
tt.Name, uc, grouping, noLbAbstract, detailExplain, tt.Format, vpcName, allVPCs, tt.VpcList)
tt.Name, uc, grouping, noLbAbstract, detailExplain, addConsistencyEdgesExternal, tt.Format, vpcName, allVPCs, tt.VpcList)
if err != nil {
return err
}
Expand All @@ -191,17 +197,23 @@ func (tt *VpcTestCommon) runTestPerUseCase(t *testing.T,
uc vpcmodel.OutputUseCase,
mode testMode,
outDir string,
grouping, noLbAbstract bool,
groupingType int,
noLbAbstract bool,
explanationArgs *vpcmodel.ExplanationArgs) error {
detailExplain := false
if explanationArgs != nil {
detailExplain = explanationArgs.Detail
}
allVpcs := len(tt.VpcList) == 0
if err := tt.initTestFileNames(uc, "", allVpcs, detailExplain, outDir, grouping, noLbAbstract); err != nil {
grouping := groupingType == vpcmodel.GroupingNoConsistencyEdges ||
groupingType == vpcmodel.GroupingWithConsistencyEdges
addConsistencyEdgesExternal := groupingType == vpcmodel.NoGroupingWithConsistencyEdges ||
groupingType == vpcmodel.GroupingWithConsistencyEdges
if err := tt.initTestFileNames(uc, "", allVpcs, detailExplain, outDir, grouping, noLbAbstract,
addConsistencyEdgesExternal); err != nil {
return err
}
og, err := vpcmodel.NewOutputGenerator(cConfigs, grouping, uc, tt.Format == vpcmodel.ARCHDRAWIO,
og, err := vpcmodel.NewOutputGenerator(cConfigs, groupingType, uc, tt.Format == vpcmodel.ARCHDRAWIO,
explanationArgs, tt.Format, !noLbAbstract)
if err != nil {
return err
Expand Down Expand Up @@ -326,7 +338,7 @@ func (tt *VpcTestCommon) setMode(mode testMode) {
}

func (tt *VpcTestCommon) runSingleCommonTest(t *testing.T, testDir string, rc commonvpc.ResourcesContainer,
grouping, noLbAbstract bool, explanationArgs *vpcmodel.ExplanationArgs) {
groupingType int, noLbAbstract bool, explanationArgs *vpcmodel.ExplanationArgs) {
// init test - set the input/output file names according to test name
tt.initTest()

Expand All @@ -335,7 +347,8 @@ func (tt *VpcTestCommon) runSingleCommonTest(t *testing.T, testDir string, rc co

// generate actual output for all use cases specified for this test
for _, uc := range tt.UseCases {
err := tt.runTestPerUseCase(t, vpcConfigs, uc, tt.Mode, testDir, grouping, noLbAbstract, explanationArgs)
err := tt.runTestPerUseCase(t, vpcConfigs, uc, tt.Mode, testDir, groupingType, noLbAbstract,
explanationArgs)
require.Equal(t, tt.ErrPerUseCase[uc], err, "comparing actual err to expected err")
}
for uc, outFile := range tt.ActualOutput {
Expand Down
2 changes: 1 addition & 1 deletion pkg/commonvpc/testfunc/explain_test_functionality.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ func (tt *VpcExplainTest) TestSingleExplain(t *testing.T, mode testMode, rc comm
tt.Format = vpcmodel.Text
t.Run(tt.Name, func(t *testing.T) {
t.Parallel()
tt.runSingleCommonTest(t, explainOut, rc, false, false, explanationArgs)
tt.runSingleCommonTest(t, explainOut, rc, vpcmodel.NoGroupingNoConsistencyEdges, false, explanationArgs)
})
}
4 changes: 3 additions & 1 deletion pkg/commonvpc/testfunc/semantic_diff_test_functionality.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/np-guard/vpc-network-config-analyzer/pkg/commonvpc"
"github.com/np-guard/vpc-network-config-analyzer/pkg/vpcmodel"
)

const secJSONOutSuffix = "_2nd.json"
Expand Down Expand Up @@ -44,7 +45,8 @@ func (tt *VpcDiffTest) runDiffSingleTest(t *testing.T, testDir string, rc common

// generate actual output for all use cases specified for this test
for _, uc := range tt.UseCases {
err := tt.runTestPerUseCase(t, vpcConfigs, uc, tt.Mode, testDir, false, false, nil)
err := tt.runTestPerUseCase(t, vpcConfigs, uc, tt.Mode, testDir, vpcmodel.NoGroupingNoConsistencyEdges, false,
nil)
require.Equal(t, tt.ErrPerUseCase[uc], err, "comparing diff's actual err to expected err")
}
for uc, outFile := range tt.ActualOutput {
Expand Down
Loading

0 comments on commit c5cdea5

Please sign in to comment.