feat: add scan_duration json field
parent
04b9206b6d
commit
56d57afb57
|
@ -64,6 +64,7 @@ type serializableAnalysis struct {
|
|||
Alerts map[string][]alerter.SerializableAlert `json:"alerts"`
|
||||
ProviderName string `json:"provider_name"`
|
||||
ProviderVersion string `json:"provider_version"`
|
||||
Duration int `json:"scan_duration"`
|
||||
}
|
||||
|
||||
type GenDriftIgnoreOptions struct {
|
||||
|
@ -107,6 +108,7 @@ func (a Analysis) MarshalJSON() ([]byte, error) {
|
|||
bla.Coverage = a.Coverage()
|
||||
bla.ProviderName = a.ProviderName
|
||||
bla.ProviderVersion = a.ProviderVersion
|
||||
bla.Duration = int(a.Duration.Seconds())
|
||||
|
||||
return json.Marshal(bla)
|
||||
}
|
||||
|
@ -167,7 +169,8 @@ func (a *Analysis) UnmarshalJSON(bytes []byte) error {
|
|||
}
|
||||
a.ProviderName = bla.ProviderName
|
||||
a.ProviderVersion = bla.ProviderVersion
|
||||
a.summary.TotalIaCSourceCount = bla.Summary.TotalIaCSourceCount
|
||||
a.SetIaCSourceCount(bla.Summary.TotalIaCSourceCount)
|
||||
a.Duration = time.Duration(bla.Duration) * time.Second
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/snyk/driftctl/pkg/filter"
|
||||
"github.com/stretchr/testify/mock"
|
||||
|
@ -1269,7 +1270,9 @@ func addSchemaToRes(res *resource.Resource, repo resource.SchemaRepositoryInterf
|
|||
|
||||
func TestAnalysis_MarshalJSON(t *testing.T) {
|
||||
goldenFile := "./testdata/output.json"
|
||||
analysis := Analysis{}
|
||||
analysis := Analysis{
|
||||
Duration: 241 * time.Second,
|
||||
}
|
||||
analysis.SetIaCSourceCount(1)
|
||||
analysis.AddManaged(
|
||||
&resource.Resource{
|
||||
|
|
|
@ -70,5 +70,6 @@
|
|||
]
|
||||
},
|
||||
"provider_name": "AWS",
|
||||
"provider_version": "2.18.5"
|
||||
"provider_version": "2.18.5",
|
||||
"scan_duration": 241
|
||||
}
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/r3labs/diff/v2"
|
||||
|
@ -23,6 +24,7 @@ func fakeAnalysis(opts analyser.AnalyzerOptions) *analyser.Analysis {
|
|||
}
|
||||
a := analyser.NewAnalysis(opts)
|
||||
a.SetIaCSourceCount(3)
|
||||
a.Duration = 12 * time.Second
|
||||
a.AddUnmanaged(
|
||||
&resource.Resource{
|
||||
Id: "unmanaged-id-1",
|
||||
|
|
|
@ -107,5 +107,6 @@
|
|||
"coverage": 33,
|
||||
"alerts": null,
|
||||
"provider_name": "AWS",
|
||||
"provider_version": "3.19.0"
|
||||
"provider_version": "3.19.0",
|
||||
"scan_duration": 12
|
||||
}
|
|
@ -26,5 +26,6 @@
|
|||
]
|
||||
},
|
||||
"provider_name": "AWS",
|
||||
"provider_version": "3.19.0"
|
||||
"provider_version": "3.19.0",
|
||||
"scan_duration": 0
|
||||
}
|
|
@ -23,5 +23,6 @@
|
|||
]
|
||||
},
|
||||
"provider_name": "AWS",
|
||||
"provider_version": "3.19.0"
|
||||
"provider_version": "3.19.0",
|
||||
"scan_duration": 0
|
||||
}
|
|
@ -91,5 +91,6 @@
|
|||
]
|
||||
},
|
||||
"provider_name": "AWS",
|
||||
"provider_version": "3.19.0"
|
||||
"provider_version": "3.19.0",
|
||||
"scan_duration": 0
|
||||
}
|
|
@ -14,5 +14,6 @@
|
|||
"coverage": 0,
|
||||
"alerts": null,
|
||||
"provider_name": "",
|
||||
"provider_version": ""
|
||||
"provider_version": "",
|
||||
"scan_duration": 0
|
||||
}
|
Loading…
Reference in New Issue