Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
Signed-off-by: troychiu <[email protected]>
  • Loading branch information
troychiu committed Nov 6, 2024
1 parent 5c811ad commit 49d325d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion flyteadmin/pkg/common/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (f *inlineFilterImpl) getGormQueryExpr(formattedField string) (GormQueryExp
}, nil
case NotLike:
return GormQueryExpr{
// WHERE field NOT LIKE %value%
// WHERE field NOT LIKE value
Query: fmt.Sprintf(notLikeQuery, formattedField),
Args: f.value,
}, nil
Expand Down
16 changes: 16 additions & 0 deletions flyteadmin/pkg/common/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func TestGetGormJoinTableQueryExpr(t *testing.T) {

var expectedArgsForFilters = map[FilterExpression]string{
Contains: "%value%",
NotLike: "value",
GreaterThan: "value",
GreaterThanOrEqual: "value",
LessThan: "value",
Expand Down Expand Up @@ -169,3 +170,18 @@ func TestWithDefaultValueFilter(t *testing.T) {
assert.Equal(t, "COALESCE(named_entity_metadata.state, 0) = ?", queryExpression.Query)
assert.Equal(t, 1, queryExpression.Args)
}

func TestNotLikeFilter(t *testing.T) {
filter, err := NewSingleValueFilter(NamedEntityMetadata, NotLike, "name", ".flytegen%")
assert.NoError(t, err)

queryExpression, err := filter.GetGormQueryExpr()
assert.NoError(t, err)
assert.Equal(t, "name NOT LIKE ?", queryExpression.Query)
assert.Equal(t, ".flytegen%", queryExpression.Args)

queryExpression, err = filter.GetGormJoinTableQueryExpr("named_entity_metadata")
assert.NoError(t, err)
assert.Equal(t, "named_entity_metadata.name NOT LIKE ?", queryExpression.Query)
assert.Equal(t, ".flytegen%", queryExpression.Args)
}
10 changes: 3 additions & 7 deletions flyteadmin/pkg/manager/impl/named_entity_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestNamedEntityManager_Get_BadRequest(t *testing.T) {
func TestNamedEntityManager_getQueryFilters(t *testing.T) {
repository := getMockRepositoryForNETest()
manager := NewNamedEntityManager(repository, getMockConfigForNETest(), mockScope.NewTestScope())
updatedFilters, err := manager.(*NamedEntityManager).getQueryFilters(core.ResourceType_TASK, "eq(state, 0)")
updatedFilters, err := manager.(*NamedEntityManager).getQueryFilters("eq(state, 0)")
assert.NoError(t, err)
assert.Len(t, updatedFilters, 1)

Expand All @@ -97,13 +97,9 @@ func TestNamedEntityManager_getQueryFilters(t *testing.T) {
assert.Equal(t, "COALESCE(state, 0) = ?", queryExp.Query)
assert.Equal(t, "0", queryExp.Args)

updatedFilters, err = manager.(*NamedEntityManager).getQueryFilters(core.ResourceType_WORKFLOW, "")
updatedFilters, err = manager.(*NamedEntityManager).getQueryFilters("")
assert.NoError(t, err)
assert.Len(t, updatedFilters, 1)
queryExp, err = updatedFilters[0].GetGormQueryExpr()
assert.NoError(t, err)
assert.Equal(t, "COALESCE(state, 0) <> ?", queryExp.Query)
assert.Equal(t, admin.NamedEntityState_SYSTEM_GENERATED, queryExp.Args)
assert.Len(t, updatedFilters, 0)
}

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

0 comments on commit 49d325d

Please sign in to comment.