-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from antfie/feature/test-coverage
Feature/test coverage
- Loading branch information
Showing
35 changed files
with
1,728 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package checks | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/antfie/scan_health/v2/report" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// Test Cases | ||
func TestGeneralRecommendations(t *testing.T) { | ||
|
||
t.Run("No Recommendations Exists", func(t *testing.T) { | ||
t.Parallel() | ||
testReport := report.Report{ | ||
Modules: []report.Module{ | ||
{Name: "test.jar", | ||
IsThirdParty: false, | ||
IsIgnored: false, | ||
Instances: []report.ModuleInstance{{ | ||
IsSelected: true, | ||
HasFatalErrors: false, | ||
}}, | ||
}, | ||
}, | ||
|
||
Issues: []report.Issue{}, | ||
Recommendations: []string{}, | ||
} | ||
|
||
generalRecommendations(&testReport) | ||
assert.Empty(t, testReport.Issues) | ||
assert.Empty(t, testReport.Recommendations) | ||
}) | ||
|
||
t.Run("No Module Recommendation Exists", func(t *testing.T) { | ||
t.Parallel() | ||
testReport := report.Report{ | ||
Modules: []report.Module{ | ||
{Name: "test.jar", | ||
IsThirdParty: false, | ||
IsIgnored: false, | ||
Instances: []report.ModuleInstance{{ | ||
IsSelected: true, | ||
HasFatalErrors: false, | ||
}}, | ||
}, | ||
}, | ||
|
||
Issues: []report.Issue{}, | ||
Recommendations: []string{ | ||
"Test Recommendation", | ||
}, | ||
} | ||
|
||
generalRecommendations(&testReport) | ||
assert.Empty(t, testReport.Issues) | ||
|
||
// No additional recommendations made | ||
assert.Equal(t, 1, len(testReport.Recommendations)) | ||
}) | ||
|
||
t.Run("Module Recommendation Exists", func(t *testing.T) { | ||
t.Parallel() | ||
testReport := report.Report{ | ||
Modules: []report.Module{ | ||
{Name: "test.jar", | ||
IsThirdParty: false, | ||
IsIgnored: false, | ||
Instances: []report.ModuleInstance{{ | ||
IsSelected: true, | ||
HasFatalErrors: false, | ||
}}, | ||
}, | ||
}, | ||
|
||
Issues: []report.Issue{}, | ||
Recommendations: []string{ | ||
"module", | ||
}, | ||
} | ||
|
||
generalRecommendations(&testReport) | ||
assert.Empty(t, testReport.Issues) | ||
|
||
// Additional recommendations are made on the presence of 'module' in the recommendations list | ||
assert.Equal(t, 6, len(testReport.Recommendations)) | ||
}) | ||
|
||
t.Run("Gradle Wrapper is the only selected one", func(t *testing.T) { | ||
t.Parallel() | ||
testReport := report.Report{ | ||
Modules: []report.Module{ | ||
{Name: "test.jar", | ||
IsThirdParty: false, | ||
IsIgnored: false, | ||
Instances: []report.ModuleInstance{{ | ||
IsSelected: false, | ||
HasFatalErrors: false, | ||
}}, | ||
}, | ||
{Name: "gradle-wrapper.jar", | ||
IsThirdParty: false, | ||
IsIgnored: false, | ||
Instances: []report.ModuleInstance{{ | ||
IsSelected: true, | ||
HasFatalErrors: false, | ||
}}, | ||
}, | ||
{Name: "test.jar", | ||
IsThirdParty: false, | ||
IsIgnored: false, | ||
Instances: []report.ModuleInstance{{ | ||
IsSelected: false, | ||
HasFatalErrors: false, | ||
}}, | ||
}, | ||
}, | ||
Issues: []report.Issue{}, | ||
} | ||
|
||
gradleWrapper(&testReport) | ||
if !assert.Equal(t, 1, len(testReport.Issues)) { | ||
t.FailNow() | ||
} | ||
|
||
assert.Contains(t, testReport.Issues[0].Description, "The only module selected ") | ||
|
||
assert.Equal(t, 1, len(testReport.Recommendations)) | ||
}) | ||
} |
Oops, something went wrong.