-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Geoffrey Bauduin <geoffrey.bauduin@corp.ovh.com>
- Loading branch information
1 parent
8ef410b
commit 7617ad3
Showing
8 changed files
with
312 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package yaorm_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/geoffreybauduin/yaorm" | ||
"github.com/geoffreybauduin/yaorm/testdata" | ||
"github.com/geoffreybauduin/yaorm/yaormfilter" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFilterApplier_ApplyLt(t *testing.T) { | ||
killDb, err := testdata.SetupTestDatabase("test") | ||
defer killDb() | ||
assert.Nil(t, err) | ||
dbp, err := yaorm.NewDBProvider("test") | ||
assert.Nil(t, err) | ||
category := &testdata.Category{Name: "category"} | ||
saveModel(t, dbp, category) | ||
category2 := &testdata.Category{Name: "category2"} | ||
saveModel(t, dbp, category2) | ||
|
||
models, err := yaorm.GenericSelectAll(dbp, testdata.NewCategoryFilter().ID(yaormfilter.Lt(category2.ID))) | ||
assert.Nil(t, err) | ||
assert.Len(t, models, 1) | ||
assert.Equal(t, models[0].(*testdata.Category).ID, category.ID) | ||
} | ||
|
||
func TestFilterApplier_ApplyLte(t *testing.T) { | ||
killDb, err := testdata.SetupTestDatabase("test") | ||
defer killDb() | ||
assert.Nil(t, err) | ||
dbp, err := yaorm.NewDBProvider("test") | ||
assert.Nil(t, err) | ||
category := &testdata.Category{Name: "category"} | ||
saveModel(t, dbp, category) | ||
category2 := &testdata.Category{Name: "category2"} | ||
saveModel(t, dbp, category2) | ||
|
||
models, err := yaorm.GenericSelectAll(dbp, testdata.NewCategoryFilter().ID(yaormfilter.Lte(category2.ID))) | ||
assert.Nil(t, err) | ||
assert.Len(t, models, 2) | ||
} | ||
|
||
func TestFilterApplier_ApplyGt(t *testing.T) { | ||
killDb, err := testdata.SetupTestDatabase("test") | ||
defer killDb() | ||
assert.Nil(t, err) | ||
dbp, err := yaorm.NewDBProvider("test") | ||
assert.Nil(t, err) | ||
category := &testdata.Category{Name: "category"} | ||
saveModel(t, dbp, category) | ||
category2 := &testdata.Category{Name: "category2"} | ||
saveModel(t, dbp, category2) | ||
|
||
models, err := yaorm.GenericSelectAll(dbp, testdata.NewCategoryFilter().ID(yaormfilter.Gt(category.ID))) | ||
assert.Nil(t, err) | ||
assert.Len(t, models, 1) | ||
assert.Equal(t, models[0].(*testdata.Category).ID, category2.ID) | ||
} | ||
|
||
func TestFilterApplier_ApplyGte(t *testing.T) { | ||
killDb, err := testdata.SetupTestDatabase("test") | ||
defer killDb() | ||
assert.Nil(t, err) | ||
dbp, err := yaorm.NewDBProvider("test") | ||
assert.Nil(t, err) | ||
category := &testdata.Category{Name: "category"} | ||
saveModel(t, dbp, category) | ||
category2 := &testdata.Category{Name: "category2"} | ||
saveModel(t, dbp, category2) | ||
|
||
models, err := yaorm.GenericSelectAll(dbp, testdata.NewCategoryFilter().ID(yaormfilter.Gte(category.ID))) | ||
assert.Nil(t, err) | ||
assert.Len(t, models, 2) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.