Skip to content

Commit

Permalink
fix is and not is test
Browse files Browse the repository at this point in the history
  • Loading branch information
mul14 committed Oct 17, 2024
1 parent c7376a1 commit 0a51aff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions pkg/db/where.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,9 @@ func (q *Query) OrIlike(column string, value string) *Query {

func (q *Query) Is(column string, value any) *Query {

isValueWhitelist(value)
if !isValueWhitelist(value) {
panic("isValueWhitelist: only \"true\", \"false\", \"null\", or \"unknown\" are allowed")

Check warning on line 409 in pkg/db/where.go

View check run for this annotation

Codecov / codecov/patch

pkg/db/where.go#L409

Added line #L409 was not covered by tests
}

if q.IsList == nil {
q.IsList = &[]string{}
Expand All @@ -421,7 +423,9 @@ func (q *Query) Is(column string, value any) *Query {

func (q *Query) NotIs(column string, value string) *Query {

isValueWhitelist(value)
if !isValueWhitelist(value) {
panic("isValueWhitelist: only \"true\", \"false\", \"null\", or \"unknown\" are allowed")

Check warning on line 427 in pkg/db/where.go

View check run for this annotation

Codecov / codecov/patch

pkg/db/where.go#L427

Added line #L427 was not covered by tests
}

if q.IsList == nil {
q.IsList = &[]string{}
Expand Down Expand Up @@ -479,7 +483,7 @@ func isValueWhitelist(value any) bool {
return true
case "unknown":
return true
default:
return false

Check warning on line 487 in pkg/db/where.go

View check run for this annotation

Codecov / codecov/patch

pkg/db/where.go#L480-L487

Added lines #L480 - L487 were not covered by tests
}

panic("isValueWhitelist: only \"true\", \"false\", \"null\", or \"unknown\" are allowed")
}
4 changes: 2 additions & 2 deletions pkg/db/where_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func TestOrIlike(t *testing.T) {
func TestIs(t *testing.T) {
q := NewQuery(&mockRaidenContext).Model(articleMockModel).Is("is_featured", "true")

if q.WhereOrList == nil {
if q.IsList == nil {
t.Error("Expected where clause not to be nil")
}

Expand All @@ -373,7 +373,7 @@ func TestIs(t *testing.T) {
func TestNotIs(t *testing.T) {
q := NewQuery(&mockRaidenContext).Model(articleMockModel).NotIs("is_featured", "true")

if q.WhereOrList == nil {
if q.IsList == nil {
t.Error("Expected where clause not to be nil")
}

Expand Down

0 comments on commit 0a51aff

Please sign in to comment.