Introduce NewAnalysis(), use it in analyzer, update fakeAnalyzer accordingly
parent
7476cfa081
commit
972eddcd79
|
@ -73,6 +73,10 @@ type GenDriftIgnoreOptions struct {
|
||||||
OutputPath string
|
OutputPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewAnalysis(options AnalyzerOptions) Analysis {
|
||||||
|
return Analysis{options: options}
|
||||||
|
}
|
||||||
|
|
||||||
func (a Analysis) MarshalJSON() ([]byte, error) {
|
func (a Analysis) MarshalJSON() ([]byte, error) {
|
||||||
bla := serializableAnalysis{}
|
bla := serializableAnalysis{}
|
||||||
for _, m := range a.managed {
|
for _, m := range a.managed {
|
||||||
|
|
|
@ -31,7 +31,7 @@ func TestConsole_Write(t *testing.T) {
|
||||||
name: "test console output",
|
name: "test console output",
|
||||||
goldenfile: "output.txt",
|
goldenfile: "output.txt",
|
||||||
args: args{analysis: func() *analyser.Analysis {
|
args: args{analysis: func() *analyser.Analysis {
|
||||||
a := fakeAnalysis()
|
a := fakeAnalysis(analyser.AnalyzerOptions{})
|
||||||
a.AddDeleted(
|
a.AddDeleted(
|
||||||
&resource.Resource{
|
&resource.Resource{
|
||||||
Id: "test-id-1",
|
Id: "test-id-1",
|
||||||
|
|
|
@ -28,7 +28,7 @@ func TestJSON_Write(t *testing.T) {
|
||||||
name: "test json output",
|
name: "test json output",
|
||||||
goldenfile: "output.json",
|
goldenfile: "output.json",
|
||||||
args: args{
|
args: args{
|
||||||
analysis: fakeAnalysis(),
|
analysis: fakeAnalysis(analyser.AnalyzerOptions{}),
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
@ -103,7 +103,7 @@ func TestJSON_Write_stdout(t *testing.T) {
|
||||||
goldenfile: "output.json",
|
goldenfile: "output.json",
|
||||||
path: "stdout",
|
path: "stdout",
|
||||||
args: args{
|
args: args{
|
||||||
analysis: fakeAnalysis(),
|
analysis: fakeAnalysis(analyser.AnalyzerOptions{}),
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
@ -113,7 +113,7 @@ func TestJSON_Write_stdout(t *testing.T) {
|
||||||
goldenfile: "output.json",
|
goldenfile: "output.json",
|
||||||
path: "/dev/stdout",
|
path: "/dev/stdout",
|
||||||
args: args{
|
args: args{
|
||||||
analysis: fakeAnalysis(),
|
analysis: fakeAnalysis(analyser.AnalyzerOptions{}),
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
@ -160,7 +160,7 @@ func TestJSON_Write_stdout(t *testing.T) {
|
||||||
|
|
||||||
func TestJSON_WriteMultiplesTimesInSameFile(t *testing.T) {
|
func TestJSON_WriteMultiplesTimesInSameFile(t *testing.T) {
|
||||||
emptyAnalysis := &analyser.Analysis{}
|
emptyAnalysis := &analyser.Analysis{}
|
||||||
longerAnalysis := fakeAnalysis()
|
longerAnalysis := fakeAnalysis(analyser.AnalyzerOptions{})
|
||||||
tempDir := t.TempDir()
|
tempDir := t.TempDir()
|
||||||
tempFile, err := ioutil.TempFile(tempDir, "result")
|
tempFile, err := ioutil.TempFile(tempDir, "result")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -16,8 +16,8 @@ import (
|
||||||
"github.com/r3labs/diff/v2"
|
"github.com/r3labs/diff/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func fakeAnalysis() *analyser.Analysis {
|
func fakeAnalysis(opts analyser.AnalyzerOptions) *analyser.Analysis {
|
||||||
a := analyser.Analysis{}
|
a := analyser.NewAnalysis(opts)
|
||||||
a.AddUnmanaged(
|
a.AddUnmanaged(
|
||||||
&resource.Resource{
|
&resource.Resource{
|
||||||
Id: "unmanaged-id-1",
|
Id: "unmanaged-id-1",
|
||||||
|
@ -110,7 +110,7 @@ func fakeAnalysis() *analyser.Analysis {
|
||||||
}
|
}
|
||||||
|
|
||||||
func fakeAnalysisWithAlerts() *analyser.Analysis {
|
func fakeAnalysisWithAlerts() *analyser.Analysis {
|
||||||
a := fakeAnalysis()
|
a := fakeAnalysis(analyser.AnalyzerOptions{})
|
||||||
a.SetAlerts(alerter.Alerts{
|
a.SetAlerts(alerter.Alerts{
|
||||||
"": []alerter.Alert{
|
"": []alerter.Alert{
|
||||||
alerts.NewRemoteAccessDeniedAlert(common.RemoteAWSTerraform, remoteerr.NewResourceListingErrorWithType(errors.New("dummy error"), "aws_vpc", "aws_vpc"), alerts.EnumerationPhase),
|
alerts.NewRemoteAccessDeniedAlert(common.RemoteAWSTerraform, remoteerr.NewResourceListingErrorWithType(errors.New("dummy error"), "aws_vpc", "aws_vpc"), alerts.EnumerationPhase),
|
||||||
|
|
Loading…
Reference in New Issue