Introduce NewAnalysis(), use it in analyzer, update fakeAnalyzer accordingly

main
Samuel Maftoul 2021-11-25 15:12:14 +01:00
parent 7476cfa081
commit 972eddcd79
4 changed files with 12 additions and 8 deletions

View File

@ -73,6 +73,10 @@ type GenDriftIgnoreOptions struct {
OutputPath string
}
func NewAnalysis(options AnalyzerOptions) Analysis {
return Analysis{options: options}
}
func (a Analysis) MarshalJSON() ([]byte, error) {
bla := serializableAnalysis{}
for _, m := range a.managed {

View File

@ -31,7 +31,7 @@ func TestConsole_Write(t *testing.T) {
name: "test console output",
goldenfile: "output.txt",
args: args{analysis: func() *analyser.Analysis {
a := fakeAnalysis()
a := fakeAnalysis(analyser.AnalyzerOptions{})
a.AddDeleted(
&resource.Resource{
Id: "test-id-1",

View File

@ -28,7 +28,7 @@ func TestJSON_Write(t *testing.T) {
name: "test json output",
goldenfile: "output.json",
args: args{
analysis: fakeAnalysis(),
analysis: fakeAnalysis(analyser.AnalyzerOptions{}),
},
wantErr: false,
},
@ -103,7 +103,7 @@ func TestJSON_Write_stdout(t *testing.T) {
goldenfile: "output.json",
path: "stdout",
args: args{
analysis: fakeAnalysis(),
analysis: fakeAnalysis(analyser.AnalyzerOptions{}),
},
wantErr: false,
},
@ -113,7 +113,7 @@ func TestJSON_Write_stdout(t *testing.T) {
goldenfile: "output.json",
path: "/dev/stdout",
args: args{
analysis: fakeAnalysis(),
analysis: fakeAnalysis(analyser.AnalyzerOptions{}),
},
wantErr: false,
},
@ -160,7 +160,7 @@ func TestJSON_Write_stdout(t *testing.T) {
func TestJSON_WriteMultiplesTimesInSameFile(t *testing.T) {
emptyAnalysis := &analyser.Analysis{}
longerAnalysis := fakeAnalysis()
longerAnalysis := fakeAnalysis(analyser.AnalyzerOptions{})
tempDir := t.TempDir()
tempFile, err := ioutil.TempFile(tempDir, "result")
if err != nil {

View File

@ -16,8 +16,8 @@ import (
"github.com/r3labs/diff/v2"
)
func fakeAnalysis() *analyser.Analysis {
a := analyser.Analysis{}
func fakeAnalysis(opts analyser.AnalyzerOptions) *analyser.Analysis {
a := analyser.NewAnalysis(opts)
a.AddUnmanaged(
&resource.Resource{
Id: "unmanaged-id-1",
@ -110,7 +110,7 @@ func fakeAnalysis() *analyser.Analysis {
}
func fakeAnalysisWithAlerts() *analyser.Analysis {
a := fakeAnalysis()
a := fakeAnalysis(analyser.AnalyzerOptions{})
a.SetAlerts(alerter.Alerts{
"": []alerter.Alert{
alerts.NewRemoteAccessDeniedAlert(common.RemoteAWSTerraform, remoteerr.NewResourceListingErrorWithType(errors.New("dummy error"), "aws_vpc", "aws_vpc"), alerts.EnumerationPhase),