Skip to content

Commit

Permalink
CR comments: syntactic changes in printing
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiriMoran committed Nov 12, 2023
1 parent b4fbe0b commit 694a8c2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
52 changes: 26 additions & 26 deletions pkg/vpcmodel/diffSubnets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ func TestSimpleSubnetSubtract(t *testing.T) {
require.Equal(t, err, nil)
newLines := strings.Count(subnet1Subtract2Str, "\n")
require.Equal(t, 5, newLines)
require.Contains(t, subnet1Subtract2Str, "diff-type: added source: subnet0 destination: subnet1 "+
"dir1: All Connections dir2: No connection, workloads-diff-info: workloads subnet0 and subnet1 added")
require.Contains(t, subnet1Subtract2Str, "diff-type: added source: subnet1 destination: subnet2 "+
"dir1: All Connections dir2: No connection, workloads-diff-info: workload subnet1 added")
require.Contains(t, subnet1Subtract2Str, "diff-type: added source: subnet2 destination: subnet3 "+
"dir1: All Connections dir2: No connection")
require.Contains(t, subnet1Subtract2Str, "diff-type: added source: subnet3 destination: subnet1 "+
"dir1: All Connections dir2: No connection, workloads-diff-info: workload subnet1 added")
require.Contains(t, subnet1Subtract2Str, "diff-type: changed source: subnet3 destination: subnet4 dir1: "+
"protocol: TCP src-ports: 10-100 dst-ports: 443 dir2: All Connections\n")
require.Contains(t, subnet1Subtract2Str, "diff-type: added, source: subnet0, destination: subnet1, "+
"config1: All Connections, config2: No connection, subnets-diff-info: subnet0 and subnet1 added")
require.Contains(t, subnet1Subtract2Str, "diff-type: added, source: subnet1, destination: subnet2, "+
"config1: All Connections, config2: No connection, subnets-diff-info: subnet1 added")
require.Contains(t, subnet1Subtract2Str, "diff-type: added, source: subnet2, destination: subnet3, "+
"config1: All Connections, config2: No connection")
require.Contains(t, subnet1Subtract2Str, "diff-type: added, source: subnet3, destination: subnet1, "+
"config1: All Connections, config2: No connection, subnets-diff-info: subnet1 added")
require.Contains(t, subnet1Subtract2Str, "diff-type: changed, source: subnet3, destination: subnet4, config1: "+
"protocol: TCP src-ports: 10-100 dst-ports: 443, config2: All Connections\n")

cfg2Subtract1, err := subnetConfigConn2.subtract(subnetConfigConn1, false)
if err != nil {
Expand All @@ -107,8 +107,8 @@ func TestSimpleSubnetSubtract(t *testing.T) {
require.Equal(t, err, nil)
subnet2Subtract1Str := cfg2Subtract1.EnhancedString(false)
fmt.Printf("cfg2Subtract1:\n%v", subnet2Subtract1Str)
require.Equal(t, subnet2Subtract1Str, "diff-type: removed source: subnet4 destination: subnet5 dir1: "+
"No connection dir2: All Connections, workloads-diff-info: workload subnet5 removed\n")
require.Equal(t, subnet2Subtract1Str, "diff-type: removed, source: subnet4, destination: subnet5, config1: "+
"No connection, config2: All Connections, subnets-diff-info: subnet5 removed\n")
}

func configSimpleIPAndSubnetSubtract() (subnetConfigConn1, subnetConfigConn2 *SubnetConfigConnectivity) {
Expand Down Expand Up @@ -174,18 +174,18 @@ func TestSimpleIPAndSubnetSubtract(t *testing.T) {
fmt.Printf("cfg1SubCfg2:\n%v\n", cfg1SubtractCfg2Str)
newLines := strings.Count(cfg1SubtractCfg2Str, "\n")
require.Equal(t, 7, newLines)
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: added source: Public Internet [250.2.4.128/25] destination: subnet2 "+
"dir1: All Connections dir2: No connection")
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: added source: Public Internet [250.2.4.16/28] destination: subnet2 "+
"dir1: All Connections dir2: No connection")
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: added source: Public Internet [250.2.4.32/27] destination: subnet2 "+
"dir1: All Connections dir2: No connection")
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: added source: Public Internet [250.2.4.4/30] destination: subnet2 "+
"dir1: All Connections dir2: No connection")
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: added source: Public Internet [250.2.4.64/26] destination: subnet2 "+
"dir1: All Connections dir2: No connection")
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: added source: Public Internet [250.2.4.8/29] destination: subnet2 "+
"dir1: All Connections dir2: No connection")
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: changed source: subnet2 destination: Public Internet [200.2.4.0/24] "+
"dir1: All Connections dir2: protocol: TCP src-ports: 0-1000 dst-ports: 0-443")
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: added, source: Public Internet [250.2.4.128/25], destination: subnet2, "+
"config1: All Connections, config2: No connection")
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: added, source: Public Internet [250.2.4.16/28], destination: subnet2, "+
"config1: All Connections, config2: No connection")
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: added, source: Public Internet [250.2.4.32/27], destination: subnet2, "+
"config1: All Connections, config2: No connection")
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: added, source: Public Internet [250.2.4.4/30], destination: subnet2, "+
"config1: All Connections, config2: No connection")
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: added, source: Public Internet [250.2.4.64/26], destination: subnet2, "+
"config1: All Connections, config2: No connection")
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: added, source: Public Internet [250.2.4.8/29], destination: subnet2, "+
"config1: All Connections, config2: No connection")
require.Contains(t, cfg1SubtractCfg2Str, "diff-type: changed, source: subnet2, destination: Public Internet [200.2.4.0/24], "+
"config1: All Connections, config2: protocol: TCP src-ports: 0-1000 dst-ports: 0-443")
}
20 changes: 10 additions & 10 deletions pkg/vpcmodel/semanticDiffSubnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ func (subnetDiff *SubnetsDiff) EnhancedString(thisMinusOther bool) string {
conn1Str = connStr(connDiff.conn2)
conn2Str = connStr(connDiff.conn1)
}
diffType, workloadDiff := diffAndWorkLoadDisc(connDiff.diff, src, dst, thisMinusOther)
printDiff := fmt.Sprintf("diff-type: %s source: %s destination: %s dir1: %s dir2: %s%s\n",
diffType, src.Name(), dst.Name(), conn1Str, conn2Str, workloadDiff)
diffType, endpointsDiff := diffAndEndpointsDisc(connDiff.diff, src, dst, thisMinusOther)
printDiff := fmt.Sprintf("diff-type: %s, source: %s, destination: %s, config1: %s, config2: %s%s\n",
diffType, src.Name(), dst.Name(), conn1Str, conn2Str, endpointsDiff)
strList = append(strList, printDiff)
}
}
Expand All @@ -210,10 +210,10 @@ func connStr(conn *common.ConnectionSet) string {
return conn.EnhancedString()
}

func diffAndWorkLoadDisc(diff DiffType, src, dst VPCResourceIntf, thisMinusOther bool) (diffDisc, workLoad string) {
func diffAndEndpointsDisc(diff DiffType, src, dst VPCResourceIntf, thisMinusOther bool) (diffDisc, workLoad string) {
const (
WorkloadDiffInfo = ", workloads-diff-info: workload"
TripleString = "%s %s %s"
SubnetsDiffInfo = ", subnets-diff-info:"
TripleString = "%s %s %s"
)
addOrRemoved := ""
if thisMinusOther {
Expand All @@ -223,12 +223,12 @@ func diffAndWorkLoadDisc(diff DiffType, src, dst VPCResourceIntf, thisMinusOther
}
switch diff {
case MissingSrcEP:
return addOrRemoved, fmt.Sprintf(TripleString, WorkloadDiffInfo, src.Name(), addOrRemoved)
return addOrRemoved, fmt.Sprintf(TripleString, SubnetsDiffInfo, src.Name(), addOrRemoved)
case MissingDstEP:
return addOrRemoved, fmt.Sprintf(TripleString, WorkloadDiffInfo, dst.Name(), addOrRemoved)
return addOrRemoved, fmt.Sprintf(TripleString, SubnetsDiffInfo, dst.Name(), addOrRemoved)
case MissingSrcDstEP:
return addOrRemoved, fmt.Sprintf("%ss %s and %s %s",
WorkloadDiffInfo, src.Name(), dst.Name(), addOrRemoved)
return addOrRemoved, fmt.Sprintf("%s %s and %s %s",
SubnetsDiffInfo, src.Name(), dst.Name(), addOrRemoved)
case MissingConnection:
return addOrRemoved, ""
case ChangedConnection:
Expand Down

0 comments on commit 694a8c2

Please sign in to comment.