Skip to content

Commit

Permalink
Merge pull request #466 from cloudskiff/rebase-v0.8
Browse files Browse the repository at this point in the history
Cherry-pick missing changes to v0.8
  • Loading branch information
eliecharra authored Apr 30, 2021
2 parents 784bfc8 + 58003a9 commit 45c6de7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func run() int {
}

func flushSentry() {
fmt.Print("Sending error report ...")
gosentry.Flush(60 * time.Second)
fmt.Printf(" done, thank you %s\n", color.RedString("❤️"))
ttl := 60 * time.Second
ok := gosentry.Flush(ttl)
logrus.WithField("timeout", ttl).WithField("success", ok).Debug("Flushed Sentry events")
}
19 changes: 11 additions & 8 deletions pkg/cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@ func NewScanCmd() *cobra.Command {
}
opts.Output = *out

filterFlag, _ := cmd.Flags().GetString("filter")
if filterFlag != "" {
expr, err := filter.BuildExpression(filterFlag)
filterFlag, _ := cmd.Flags().GetStringArray("filter")

if len(filterFlag) > 1 {
return errors.New("Filter flag should be specified only once")
}

if len(filterFlag) == 1 && filterFlag[0] != "" {
expr, err := filter.BuildExpression(filterFlag[0])
if err != nil {
return errors.Wrap(err, "unable to parse filter expression")
}
Expand All @@ -81,16 +86,14 @@ func NewScanCmd() *cobra.Command {
}

fl := cmd.Flags()
fl.BoolP(
fl.Bool(
"quiet",
"",
false,
"Do not display anything but scan results",
)
fl.StringP(
fl.StringArray(
"filter",
"",
"",
[]string{},
"JMESPath expression to filter on\n"+
"Examples : \n"+
" - Type == 'aws_s3_bucket' (will filter only s3 buckets)\n"+
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func TestScanCmd_Invalid(t *testing.T) {
{args: []string{"scan", "--from", "tfstate+foobar://test"}, expected: "Unsupported IaC backend 'foobar': \nAccepted values are: s3,http,https"},
{args: []string{"scan", "--from", "tfstate:///tmp/test", "--from", "tfstate+toto://test"}, expected: "Unsupported IaC backend 'toto': \nAccepted values are: s3,http,https"},
{args: []string{"scan", "--filter", "Type='test'"}, expected: "unable to parse filter expression: SyntaxError: Expected tRbracket, received: tUnknown"},
{args: []string{"scan", "--filter", "Type='test'", "--filter", "Type='test2'"}, expected: "Filter flag should be specified only once"},
}

for _, tt := range cases {
Expand Down
7 changes: 5 additions & 2 deletions pkg/output/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ func (p *progress) Stop() {
}

func (p *progress) Inc() {
if p.started.Load() {
p.count.Inc()
if lastVal := p.count.Load(); !p.started.Load() {
logrus.Debug("Progress received a tic after stopping. Restarting...")
p.Start()
p.count.Store(lastVal)
}
p.count.Inc()
}

func (p *progress) Val() uint64 {
Expand Down
14 changes: 9 additions & 5 deletions pkg/output/progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ import (
func TestProgressTimeoutDoesNotInc(t *testing.T) {
progress := NewProgress()
progress.Start()
progress.Inc()
progress.Stop() // should not hang
progress.Inc() // should not hang or inc
assert.Equal(t, uint64(0), progress.Val())
progress.Inc() // should restart progress and inc
assert.Equal(t, uint64(2), progress.Val())
assert.Equal(t, true, progress.started.Load())

progress.Stop()
assert.Equal(t, false, progress.started.Load())
}

func TestProgressTimeoutDoesNotHang(t *testing.T) {
Expand All @@ -21,10 +26,9 @@ func TestProgressTimeoutDoesNotHang(t *testing.T) {
time.Sleep(progressTimeout)
for progress.started.Load() == true {
}
progress.Inc() // should not hang or inc
progress.Inc() // should not hang but inc
progress.Stop() // should not hang
assert.Equal(t, uint64(0), progress.Val())

assert.Equal(t, uint64(1), progress.Val())
}

func TestProgress(t *testing.T) {
Expand Down

0 comments on commit 45c6de7

Please sign in to comment.