Skip to content

Commit

Permalink
feat: fix sonarlint
Browse files Browse the repository at this point in the history
  • Loading branch information
mariolg committed Nov 15, 2023
1 parent 7fbafc7 commit 977c396
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 6 additions & 1 deletion steps/mongo/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ import (
"go.mongodb.org/mongo-driver/mongo/options"
)

var (
EMPTY = "[EMPTY]"
NULL = "[NULL]"
)

// Session contains the information of a MongoDB session.
type Session struct {

Expand Down Expand Up @@ -330,7 +335,7 @@ func GetFilterConverted(field, value string) primitive.M {
}

// If the passed value is "[EMPTY]" or "[NULL]", it evaluates to nil
if value == "[EMPTY]" || value == "[NULL]" {
if value == EMPTY || value == NULL {
return bson.M{field: nil}
}

Expand Down
11 changes: 6 additions & 5 deletions steps/mongo/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"go.mongodb.org/mongo-driver/mongo"
)

var ISBOOLEAN = "is_boolean"

func TestPing(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -363,8 +365,7 @@ func TestGetFilter(t *testing.T) {
})
t.Run("Create filter with nil value", func(t *testing.T) {
key := "name"
var value interface{} = nil
filter := GetFilter(key, value)
filter := GetFilter(key, nil)
expectedFilter := bson.M{"name": nil}
if !reflect.DeepEqual(filter, expectedFilter) {
t.Errorf("Expected filter: %v, but got: %v", expectedFilter, filter)
Expand All @@ -374,7 +375,7 @@ func TestGetFilter(t *testing.T) {

func TestGetFilterConverted(t *testing.T) {
t.Run("Convert to boolean (true)", func(t *testing.T) {
field := "is_boolean"
field := ISBOOLEAN
value := "true"
filter := GetFilterConverted(field, value)
expectedFilter := primitive.M{field: true}
Expand All @@ -383,7 +384,7 @@ func TestGetFilterConverted(t *testing.T) {
}
})
t.Run("Convert to boolean (false)", func(t *testing.T) {
field := "is_boolean"
field := ISBOOLEAN
value := "false"
filter := GetFilterConverted(field, value)
expectedFilter := primitive.M{field: false}
Expand Down Expand Up @@ -411,7 +412,7 @@ func TestGetFilterConverted(t *testing.T) {
})
t.Run("Convert to nil (empty)", func(t *testing.T) {
field := "nil or empty"
value := "[EMPTY]"
value := EMPTY
filter := GetFilterConverted(field, value)
expectedFilter := primitive.M{field: nil}
if filter[field] != expectedFilter[field] {
Expand Down

0 comments on commit 977c396

Please sign in to comment.