Skip to content

Commit 7e33a2b

Browse files
committed
towards full support in multiVPC
1 parent 6063eaf commit 7e33a2b

File tree

3 files changed

+37
-42
lines changed

3 files changed

+37
-42
lines changed

cmd/analyzer/subcmds/lint.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,10 @@ func lintVPCConfigs(cmd *cobra.Command, inArgs *inArgs) error {
2929
cmd.SilenceUsage = true // if we got this far, flags are syntactically correct, so no need to print usage
3030
cmd.SilenceErrors = true // also, error will be printed to logger in main(), so no need for cobra to also print it
3131

32-
vpcConfigs, err := buildConfigs(inArgs)
32+
multiConfigs, err := buildConfigs(inArgs)
3333
if err != nil {
3434
return err
3535
}
36-
// takes the first vpcConfig, for now
37-
for _, vpcConfig := range vpcConfigs.Configs() {
38-
linter.LinterExecute(vpcConfig)
39-
return nil
40-
}
36+
linter.LinterExecute(multiConfigs.Configs())
4137
return nil
4238
}

pkg/ibmvpc/lint_test.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (tt *vpcGeneralTest) runLintTest(t *testing.T) {
6969
vpcConfigs := getVPCConfigs(t, tt, true)
7070

7171
// generate actual output for all use cases specified for this test
72-
err := runLintTestPerUseCase(t, tt, vpcConfigs, lintOut)
72+
err := runLintTestPerUseCase(t, tt, vpcConfigs.Configs(), lintOut)
7373
require.Equal(t, tt.errPerUseCase[vpcmodel.AllEndpoints], err, "comparing actual err to expected err")
7474
for uc, outFile := range tt.actualOutput {
7575
fmt.Printf("test %s use-case %d - generated output file: %s\n", tt.name, uc, outFile)
@@ -79,19 +79,13 @@ func (tt *vpcGeneralTest) runLintTest(t *testing.T) {
7979
// runExplainTestPerUseCase executes lint for the required use case and compares/generates the output
8080
func runLintTestPerUseCase(t *testing.T,
8181
tt *vpcGeneralTest,
82-
cConfigs *vpcmodel.MultipleVPCConfigs,
82+
cConfigs map[string]*vpcmodel.VPCConfig,
8383
outDir string) error {
8484
// output use case is not significant here, but being used so that lint test can rely on existing mechanism
8585
if err := initLintTestFileNames(tt, outDir); err != nil {
8686
return err
8787
}
88-
// todo: support multiCPV config
89-
var myConfig *vpcmodel.VPCConfig
90-
for _, config := range cConfigs.Configs() {
91-
myConfig = config
92-
continue // todo: tmp
93-
}
94-
_, actualOutput := linter.LinterExecute(myConfig)
88+
_, actualOutput := linter.LinterExecute(cConfigs)
9589
if err := compareOrRegenerateOutputPerTest(t, tt.mode, actualOutput, tt, vpcmodel.AllEndpoints); err != nil {
9690
return err
9791
}

pkg/linter/linterExecute.go

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,39 @@ const issues = " issues:"
1717

1818
// LinterExecute executes linters one by one
1919
// todo: mechanism for disabling/enabling lint checks
20-
// todo: handle multiConfig
21-
func LinterExecute(config *vpcmodel.VPCConfig) (issueFound bool, resString string) {
22-
blinter := basicLinter{
23-
config: config,
24-
}
25-
linters := []linter{
26-
&filterRuleSplitSubnet{basicLinter: blinter},
27-
}
28-
issueFound = false
29-
resString = "linting results for " + config.VPC.Name()
30-
underline := strings.Repeat("~", len(resString))
31-
resString += "\n" + underline + "\n\n"
32-
for _, thisLinter := range linters {
33-
lintIssues, err := thisLinter.check()
34-
if err != nil {
35-
fmt.Printf("Lint %s got an error %s. Skipping this lint\n", thisLinter.getName(), err.Error())
36-
continue
20+
func LinterExecute(configsMap map[string]*vpcmodel.VPCConfig) (issueFound bool, resString string) {
21+
for _, config := range configsMap {
22+
if config.IsMultipleVPCsConfig {
23+
continue // no use in executing lint on dummy vpcs
24+
}
25+
blinter := basicLinter{
26+
config: config,
27+
}
28+
linters := []linter{
29+
&filterRuleSplitSubnet{basicLinter: blinter},
3730
}
38-
if len(lintIssues) == 0 {
39-
fmt.Printf("no lint %s issues\n", thisLinter.getName())
40-
continue
41-
} else {
42-
issueFound = true
31+
issueFound = false
32+
resString = "linting results for " + config.VPC.Name()
33+
underline := strings.Repeat("~", len(resString))
34+
resString += "\n" + underline + "\n\n"
35+
for _, thisLinter := range linters {
36+
lintIssues, err := thisLinter.check()
37+
if err != nil {
38+
fmt.Printf("Lint %s got an error %s. Skipping this lint\n", thisLinter.getName(), err.Error())
39+
continue
40+
}
41+
if len(lintIssues) == 0 {
42+
fmt.Printf("no lint %s issues\n", thisLinter.getName())
43+
continue
44+
} else {
45+
issueFound = true
46+
}
47+
resString += fmt.Sprintf("%s%s\n", thisLinter.getName(), issues) +
48+
strings.Repeat("-", len(thisLinter.getName())+len(issues)) + "\n" +
49+
strings.Join(lintIssues, "")
4350
}
44-
resString += fmt.Sprintf("%s%s\n", thisLinter.getName(), issues) +
45-
strings.Repeat("-", len(thisLinter.getName())+len(issues)) + "\n" +
46-
strings.Join(lintIssues, "")
51+
fmt.Printf("%v", resString)
52+
return issueFound, resString
4753
}
48-
fmt.Printf("%v", resString)
49-
return issueFound, resString
54+
return false, ""
5055
}

0 commit comments

Comments
 (0)