Skip to content

Commit

Permalink
fix one bats test
Browse files Browse the repository at this point in the history
  • Loading branch information
blotus committed Nov 18, 2024
1 parent e8e0060 commit 4ee4e6a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions cmd/crowdsec-cli/clibouncer/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/crowdsecurity/crowdsec/pkg/database"
"github.com/crowdsecurity/crowdsec/pkg/database/ent"
)

Expand All @@ -32,11 +31,11 @@ func (cli *cliBouncers) delete(ctx context.Context, bouncers []string, ignoreMis
for _, bouncerName := range bouncers {
bouncer, err := cli.db.SelectBouncerByName(ctx, bouncerName)
if err != nil {
var notFoundErr *database.BouncerNotFoundError
var notFoundErr *ent.NotFoundError

Check warning on line 34 in cmd/crowdsec-cli/clibouncer/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/clibouncer/delete.go#L27-L34

Added lines #L27 - L34 were not covered by tests
if ignoreMissing && errors.As(err, &notFoundErr) {
continue

Check warning on line 36 in cmd/crowdsec-cli/clibouncer/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/clibouncer/delete.go#L36

Added line #L36 was not covered by tests
}
return fmt.Errorf("unable to delete bouncer: %w", err)
return fmt.Errorf("unable to delete bouncer %s: %w", bouncerName, err)

Check warning on line 38 in cmd/crowdsec-cli/clibouncer/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/clibouncer/delete.go#L38

Added line #L38 was not covered by tests
}

if bouncer.AutoCreated {
Expand All @@ -50,16 +49,16 @@ func (cli *cliBouncers) delete(ctx context.Context, bouncers []string, ignoreMis
}
//Try to find all child bouncers and delete them
for _, childBouncer := range allBouncers {
if strings.HasPrefix(childBouncer.Name, bouncerName+"@") {
if strings.HasPrefix(childBouncer.Name, bouncerName+"@") && childBouncer.AutoCreated {
if err := cli.db.DeleteBouncer(ctx, childBouncer.Name); err != nil {
return fmt.Errorf("unable to delete bouncer: %w", err)
return fmt.Errorf("unable to delete bouncer %s: %w", childBouncer.Name, err)
}
log.Infof("bouncer '%s' deleted successfully", childBouncer.Name)

Check warning on line 56 in cmd/crowdsec-cli/clibouncer/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/clibouncer/delete.go#L51-L56

Added lines #L51 - L56 were not covered by tests
}
}

if err := cli.db.DeleteBouncer(ctx, bouncerName); err != nil {
return fmt.Errorf("unable to delete bouncer: %w", err)
return fmt.Errorf("unable to delete bouncer %s: %w", bouncerName, err)

Check warning on line 61 in cmd/crowdsec-cli/clibouncer/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/clibouncer/delete.go#L60-L61

Added lines #L60 - L61 were not covered by tests
}

log.Infof("bouncer '%s' deleted successfully", bouncerName)

Check warning on line 64 in cmd/crowdsec-cli/clibouncer/delete.go

View check run for this annotation

Codecov / codecov/patch

cmd/crowdsec-cli/clibouncer/delete.go#L64

Added line #L64 was not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion test/bats/10_bouncers.bats
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ teardown() {
@test "delete non-existent bouncer" {
# this is a fatal error, which is not consistent with "machines delete"
rune -1 cscli bouncers delete something
assert_stderr --partial "unable to delete bouncer: 'something' does not exist"
assert_stderr --partial "unable to delete bouncer something: ent: bouncer not found"
rune -0 cscli bouncers delete something --ignore-missing
refute_stderr
}
Expand Down

0 comments on commit 4ee4e6a

Please sign in to comment.