Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

765 test seperation #875

Merged
merged 37 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
121d976
seperated tests to report, lint and explain with implied refactoring
ShiriMoran Sep 16, 2024
1ced148
some renaming
ShiriMoran Sep 16, 2024
6bdce6c
added diff tests
ShiriMoran Sep 16, 2024
9d4e081
lint
ShiriMoran Sep 16, 2024
f9d6e9d
lint
ShiriMoran Sep 16, 2024
9e57960
lint
ShiriMoran Sep 16, 2024
35c02cb
lint
ShiriMoran Sep 16, 2024
813a057
lint
ShiriMoran Sep 17, 2024
02ef5ec
functions that need not be exported
ShiriMoran Sep 17, 2024
b26d615
refactoring, avoid dup code
ShiriMoran Sep 17, 2024
f6e5878
refactoring, avoid dup code
ShiriMoran Sep 17, 2024
586af89
refactor - avoid dup code
ShiriMoran Sep 17, 2024
bdf23ba
refactor - avoid dup code
ShiriMoran Sep 17, 2024
d23221e
lint
ShiriMoran Sep 17, 2024
f9a6bc4
removed redundant file; unexported local functions
ShiriMoran Sep 17, 2024
a193fbf
restored deleted by mistake
ShiriMoran Sep 17, 2024
45532d8
Merge branch 'main' into 765_test_seperation
ShiriMoran Sep 18, 2024
a7bb97d
bug fix
ShiriMoran Sep 18, 2024
cd7e013
Merge branch 'main' into 765_test_seperation
ShiriMoran Sep 18, 2024
9209805
renaming
ShiriMoran Sep 18, 2024
12cb114
Merge branch 'main' into 765_test_seperation
ShiriMoran Sep 18, 2024
34e3343
merge with main manual part
ShiriMoran Sep 18, 2024
777fb12
Merge branch 'main' into 765_test_seperation
ShiriMoran Sep 19, 2024
825a1b0
Merge branch 'main' into 765_test_seperation
ShiriMoran Sep 19, 2024
5ca0f21
Merge branch 'main' into 765_test_seperation
ShiriMoran Sep 23, 2024
db5fef6
merged aws lint tests
ShiriMoran Sep 23, 2024
5e8eb3a
merged aws lint tests
ShiriMoran Sep 23, 2024
4613d07
CR
ShiriMoran Sep 23, 2024
1a5d1ac
CR
ShiriMoran Sep 23, 2024
5024177
CR: restored VpcAnalysisTest
ShiriMoran Sep 24, 2024
972cd15
Merge branch 'main' into 765_test_seperation
ShiriMoran Sep 24, 2024
fe03e50
CR: grouping and noLbsAbstraction relevant only to analysis
ShiriMoran Sep 24, 2024
e704257
CR: move tests functionality to a dedicated package
ShiriMoran Sep 24, 2024
fbc4b5a
lint
ShiriMoran Sep 24, 2024
6fd8524
cr: move testfunc under commonvpc
ShiriMoran Sep 24, 2024
3cd58be
lint
ShiriMoran Sep 24, 2024
b9ce61f
remove redundant function
ShiriMoran Sep 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 39 additions & 27 deletions pkg/awsvpc/analysis_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,61 +10,73 @@ import (
"fmt"
"testing"

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

const analysisOut = "analysis_out"

var tests = []*commonvpc.VpcGeneralTest{
var tests = []*testfunc.VpcAnalysisTest{
{
InputConfig: "basic_config_with_sg",
UseCases: []vpcmodel.OutputUseCase{vpcmodel.AllEndpoints, vpcmodel.AllSubnets},
Format: vpcmodel.Text,
VpcTestCommon: testfunc.VpcTestCommon{
InputConfig: "basic_config_with_sg",
UseCases: []vpcmodel.OutputUseCase{vpcmodel.AllEndpoints, vpcmodel.AllSubnets},
Format: vpcmodel.Text,
},
},
{
InputConfig: "aws_sg_1",
UseCases: []vpcmodel.OutputUseCase{vpcmodel.AllEndpoints, vpcmodel.AllSubnets},
Format: vpcmodel.Text,
VpcTestCommon: testfunc.VpcTestCommon{
InputConfig: "aws_sg_1",
UseCases: []vpcmodel.OutputUseCase{vpcmodel.AllEndpoints, vpcmodel.AllSubnets},
Format: vpcmodel.Text,
},
},
{
InputConfig: "aws_sg_1",
UseCases: []vpcmodel.OutputUseCase{vpcmodel.AllEndpoints},
Format: vpcmodel.HTML,
VpcTestCommon: testfunc.VpcTestCommon{
InputConfig: "aws_sg_1",
UseCases: []vpcmodel.OutputUseCase{vpcmodel.AllEndpoints},
Format: vpcmodel.HTML,
},
},
{
InputConfig: "aws_acl_1",
UseCases: []vpcmodel.OutputUseCase{vpcmodel.AllEndpoints, vpcmodel.AllSubnets},
Format: vpcmodel.Text,
VpcTestCommon: testfunc.VpcTestCommon{
InputConfig: "aws_acl_1",
UseCases: []vpcmodel.OutputUseCase{vpcmodel.AllEndpoints, vpcmodel.AllSubnets},
Format: vpcmodel.Text,
},
},
{
InputConfig: "aws_mixed",
UseCases: []vpcmodel.OutputUseCase{vpcmodel.AllEndpoints, vpcmodel.AllSubnets},
Format: vpcmodel.Text,
VpcTestCommon: testfunc.VpcTestCommon{
InputConfig: "aws_mixed",
UseCases: []vpcmodel.OutputUseCase{vpcmodel.AllEndpoints, vpcmodel.AllSubnets},
Format: vpcmodel.Text,
},
},
{
InputConfig: "aws_mixed",
UseCases: []vpcmodel.OutputUseCase{vpcmodel.AllEndpoints},
Format: vpcmodel.HTML,
VpcTestCommon: testfunc.VpcTestCommon{
InputConfig: "aws_mixed",
UseCases: []vpcmodel.OutputUseCase{vpcmodel.AllEndpoints},
Format: vpcmodel.HTML,
},
},
}

// uncomment the function below to run for updating the expected output
/*
func TestAllWithGeneration(t *testing.T) {

/*func TestReportWithGeneration(t *testing.T) {
// tests is the list of tests to run
for testIdx := range tests {
tt := tests[testIdx]
commonvpc.TestAll(tt, t, commonvpc.OutputGeneration, &AWSresourcesContainer{}, analysisOut, tt.InputConfig)
tt.TestAnalysisSingleTest(t, testfunc.OutputGeneration, &AWSresourcesContainer{}, analysisOut, tt.InputConfig)
}
fmt.Println("done")
}
*/
func TestAllWithComparison(t *testing.T) {
}*/

func TestReportWithComparison(t *testing.T) {
// tests is the list of tests to run
for testIdx := range tests {
tt := tests[testIdx]
commonvpc.TestAll(tt, t, commonvpc.OutputComparison, &AWSresourcesContainer{}, analysisOut, tt.InputConfig)
tt.TestAnalysisSingleTest(t, testfunc.OutputComparison, &AWSresourcesContainer{}, analysisOut, tt.InputConfig)
}
fmt.Println("done")
}
80 changes: 39 additions & 41 deletions pkg/awsvpc/explainability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,111 +10,109 @@ import (
"fmt"
"testing"

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

var explainTests = []*commonvpc.VpcGeneralTest{
var explainTests = []*testfunc.VpcExplainTest{
// existing connection between two endpoints of different subnets
{
Name: "ip_to_ip",
InputConfig: "aws_sg_1",
VpcTestCommon: testfunc.VpcTestCommon{
Name: "ip_to_ip",
InputConfig: "aws_sg_1",
},
ESrc: "10.240.40.217",
EDst: "10.240.20.43",
Format: vpcmodel.Text,
DetailExplain: true,
},
// non-existing connection between two endpoints of different subnets due to one of the nacls
{
Name: "nacl_blocking",
InputConfig: "aws_mixed",
VpcTestCommon: testfunc.VpcTestCommon{
Name: "nacl_blocking",
InputConfig: "aws_mixed",
},
ESrc: "10.240.2.28",
EDst: "10.240.32.122",
Format: vpcmodel.Text,
DetailExplain: true,
},
// existing sub-connection between two endpoints of the same subnet
// todo: https://github.com/np-guard/vpc-network-config-analyzer/issues/859
{
Name: "same_subnet_partial_connection",
InputConfig: "aws_mixed",
VpcTestCommon: testfunc.VpcTestCommon{
Name: "same_subnet_partial_connection",
InputConfig: "aws_mixed",
},
ESrc: "10.240.32.122",
EDst: "10.240.32.91",
Format: vpcmodel.Text,
DetailExplain: true,
},
// no connection between two endpoints of the same subnet
{
Name: "subnet_to_subnet",
InputConfig: "aws_mixed",
VpcTestCommon: testfunc.VpcTestCommon{
Name: "subnet_to_subnet",
InputConfig: "aws_mixed",
},
ESrc: "private2",
EDst: "private1",
Format: vpcmodel.Text,
DetailExplain: true,
},
// connection to the public internet blocked by sg and private subnet
{
Name: "to_external_private_subnet",
InputConfig: "aws_sg_1",
VpcTestCommon: testfunc.VpcTestCommon{
Name: "to_external_private_subnet",
InputConfig: "aws_sg_1",
},
ESrc: "10.240.20.245",
EDst: "161.26.0.0",
Format: vpcmodel.Text,
DetailExplain: true,
},
// existing connection to the public internet
{
Name: "to_external_public_subnet",
InputConfig: "aws_sg_1",
VpcTestCommon: testfunc.VpcTestCommon{
Name: "to_external_public_subnet",
InputConfig: "aws_sg_1",
},
ESrc: "10.240.10.42",
EDst: "161.26.0.0",
Format: vpcmodel.Text,
DetailExplain: true,
},
// existing connection from the public internet
{
Name: "from_external_public_subnet",
InputConfig: "aws_mixed",
VpcTestCommon: testfunc.VpcTestCommon{
Name: "from_external_public_subnet",
InputConfig: "aws_mixed",
},
ESrc: "147.235.0.0/16",
EDst: "10.240.0.96",
Format: vpcmodel.Text,
DetailExplain: true,
},
// connection to the public internet blocked only by private subnet
{
Name: "to_external_blocked_only_private_subnet",
InputConfig: "aws_sg_1_allow_sg_private",
VpcTestCommon: testfunc.VpcTestCommon{
Name: "to_external_blocked_only_private_subnet",
InputConfig: "aws_sg_1_allow_sg_private",
},
ESrc: "10.240.20.245",
EDst: "161.26.0.0",
Format: vpcmodel.Text,
DetailExplain: true,
},
}

func TestAll(t *testing.T) {
func TestExplainWithComparsion(t *testing.T) {
// explainTests is the list of tests to run
for testIdx := range explainTests {
tt := explainTests[testIdx]
t.Run(tt.Name, func(t *testing.T) {
t.Parallel()
rc := &AWSresourcesContainer{}
commonvpc.RunExplainTest(tt, t, rc)
})
tt.TestSingleExplain(t, testfunc.OutputComparison, &AWSresourcesContainer{}, tt.Name)
}
fmt.Println("done")
}

// uncomment the function below for generating the expected output files instead of comparing
/*
func TestAllWithGeneration(t *testing.T) {

/*func TestExplainWithGeneration(t *testing.T) {
// tests is the list of tests to run
for testIdx := range explainTests {
tt := explainTests[testIdx]
tt.Mode = commonvpc.OutputGeneration
t.Run(tt.Name, func(t *testing.T) {
t.Parallel()
rc := &AWSresourcesContainer{}
commonvpc.RunExplainTest(tt, t,rc)
})
tt.TestSingleExplain(t, commonvpc.OutputGeneration, &AWSresourcesContainer{}, tt.Name)
}
fmt.Println("done")
}*/
38 changes: 22 additions & 16 deletions pkg/awsvpc/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,45 @@ import (
"fmt"
"testing"

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

var lintTests = []*commonvpc.VpcGeneralTest{
var lintTests = []*testfunc.VpcLintTest{
{
Name: "aws_acl1",
InputConfig: "aws_acl_1",
Enable: []string{"sg-split-subnet"},
VpcTestCommon: testfunc.VpcTestCommon{
Name: "aws_acl1",
InputConfig: "aws_acl_1",
},
Enable: []string{"sg-split-subnet"},
},
{
Name: "aws_mixed",
InputConfig: "aws_mixed",
Enable: []string{"sg-split-subnet"},
VpcTestCommon: testfunc.VpcTestCommon{
Name: "aws_mixed",
InputConfig: "aws_mixed",
},
Enable: []string{"sg-split-subnet"},
},
{
Name: "aws_sg_1",
InputConfig: "aws_sg_1",
Enable: []string{"sg-split-subnet"},
VpcTestCommon: testfunc.VpcTestCommon{
Name: "aws_sg_1",
InputConfig: "aws_sg_1",
},
Enable: []string{"sg-split-subnet"},
Disable: []string{"nacl-split-subnet", "subnet-cidr-overlap", "nacl-unattached",
"sg-unattached", "sg-rule-cidr-out-of-range", "nacl-rule-cidr-out-of-range",
"tcp-response-blocked", "sg-rule-implied", "nacl-rule-shadowed"},
},
}

func TestAllLint(t *testing.T) {
func TestLintWithComparsion(t *testing.T) {
// lintTests is the list of tests to run
for testIdx := range lintTests {
tt := lintTests[testIdx]
tt.Mode = commonvpc.OutputComparison
tt.Mode = testfunc.OutputComparison
t.Run(tt.Name, func(t *testing.T) {
t.Parallel()
rc := &AWSresourcesContainer{}
commonvpc.RunLintTest(tt, t, rc)
tt.TestSingleLint(t, rc)
})
}
fmt.Println("done")
Expand All @@ -54,11 +60,11 @@ func TestAllLint(t *testing.T) {
// tests is the list of tests to run
for testIdx := range lintTests {
tt := lintTests[testIdx]
tt.Mode = commonvpc.OutputGeneration
tt.Mode = testfunc.OutputGeneration
t.Run(tt.Name, func(t *testing.T) {
t.Parallel()
rc := &AWSresourcesContainer{}
commonvpc.RunLintTest(tt, t, rc)
tt.TestSingleLint(t, rc)
})
}
fmt.Println("done")
Expand Down
29 changes: 29 additions & 0 deletions pkg/commonvpc/testfunc/analysis_output_test_functionality.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2023- IBM Inc. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/

package testfunc

import (
_ "embed"
"testing"

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

type VpcAnalysisTest struct {
VpcTestCommon
Grouping bool
NoLbAbstract bool
}

func (tt *VpcAnalysisTest) TestAnalysisSingleTest(t *testing.T, mode testMode, rc commonvpc.ResourcesContainer, testDir, testName string) {
tt.Name = testName
tt.setMode(mode)
t.Run(tt.Name, func(t *testing.T) {
t.Parallel()
tt.runSingleCommonTest(t, testDir, rc, tt.Grouping, tt.NoLbAbstract, nil)
})
}
Loading