Apigw store tests
This commit is contained in:
@@ -1,11 +1,85 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/filter"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func testApigwFilter(t *testing.T, s store.ApigwFilters) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
new = &types.ApigwFilter{
|
||||
ID: 42,
|
||||
Enabled: true,
|
||||
CreatedAt: time.Now(),
|
||||
CreatedBy: 1}
|
||||
disabled = &types.ApigwFilter{
|
||||
ID: 4242,
|
||||
Enabled: false,
|
||||
CreatedAt: time.Now(),
|
||||
CreatedBy: 1}
|
||||
)
|
||||
|
||||
t.Run("create", func(t *testing.T) {
|
||||
req := require.New(t)
|
||||
req.NoError(s.TruncateApigwFilters(ctx))
|
||||
req.NoError(s.CreateApigwFilter(ctx, new))
|
||||
})
|
||||
|
||||
t.Run("update", func(t *testing.T) {
|
||||
req := require.New(t)
|
||||
req.NoError(s.TruncateApigwFilters(ctx))
|
||||
req.NoError(s.UpdateApigwFilter(ctx, new))
|
||||
})
|
||||
|
||||
t.Run("search", func(t *testing.T) {
|
||||
req := require.New(t)
|
||||
req.NoError(s.TruncateApigwFilters(ctx))
|
||||
req.NoError(s.CreateApigwFilter(ctx,
|
||||
new,
|
||||
))
|
||||
|
||||
set, _, err := s.SearchApigwFilters(ctx, types.ApigwFilterFilter{})
|
||||
req.NoError(err)
|
||||
req.Len(set, 1)
|
||||
})
|
||||
|
||||
t.Run("search only disabled", func(t *testing.T) {
|
||||
req := require.New(t)
|
||||
req.NoError(s.TruncateApigwFilters(ctx))
|
||||
req.NoError(s.CreateApigwFilter(ctx,
|
||||
disabled,
|
||||
))
|
||||
|
||||
set, _, err := s.SearchApigwFilters(ctx, types.ApigwFilterFilter{
|
||||
Disabled: filter.StateExclusive,
|
||||
})
|
||||
|
||||
req.NoError(err)
|
||||
req.Len(set, 1)
|
||||
req.Equal(set[0].ID, disabled.ID)
|
||||
})
|
||||
|
||||
t.Run("search enabled and disabled", func(t *testing.T) {
|
||||
req := require.New(t)
|
||||
req.NoError(s.TruncateApigwFilters(ctx))
|
||||
req.NoError(s.CreateApigwFilter(ctx,
|
||||
new,
|
||||
disabled,
|
||||
))
|
||||
|
||||
set, _, err := s.SearchApigwFilters(ctx, types.ApigwFilterFilter{
|
||||
Disabled: filter.StateInclusive,
|
||||
})
|
||||
|
||||
req.NoError(err)
|
||||
req.Len(set, 2)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,11 +1,111 @@
|
||||
package tests
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/filter"
|
||||
"github.com/cortezaproject/corteza-server/store"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
_ "github.com/joho/godotenv/autoload"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func testApigwRoute(t *testing.T, s store.ApigwRoutes) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
new = &types.ApigwRoute{
|
||||
ID: 42,
|
||||
Endpoint: "/foo",
|
||||
Enabled: true,
|
||||
CreatedBy: 1}
|
||||
|
||||
disabled = &types.ApigwRoute{
|
||||
ID: 4242,
|
||||
Endpoint: "/foo_disabled",
|
||||
Enabled: false,
|
||||
CreatedBy: 1}
|
||||
)
|
||||
|
||||
t.Run("create", func(t *testing.T) {
|
||||
req := require.New(t)
|
||||
req.NoError(s.TruncateApigwRoutes(ctx))
|
||||
req.NoError(s.CreateApigwRoute(ctx, new))
|
||||
})
|
||||
|
||||
t.Run("lookup by ID", func(t *testing.T) {
|
||||
req := require.New(t)
|
||||
req.NoError(s.TruncateApigwRoutes(ctx))
|
||||
req.NoError(s.CreateApigwRoute(ctx, new))
|
||||
fetched, err := s.LookupApigwRouteByID(ctx, new.ID)
|
||||
req.NoError(err)
|
||||
req.Equal(new.ID, fetched.ID)
|
||||
req.Equal(new.Endpoint, fetched.Endpoint)
|
||||
req.NotNil(fetched.CreatedAt)
|
||||
req.Nil(fetched.UpdatedAt)
|
||||
req.Nil(fetched.DeletedAt)
|
||||
})
|
||||
|
||||
t.Run("lookup by endpoint", func(t *testing.T) {
|
||||
req := require.New(t)
|
||||
req.NoError(s.TruncateApigwRoutes(ctx))
|
||||
req.NoError(s.CreateApigwRoute(ctx, new))
|
||||
fetched, err := s.LookupApigwRouteByEndpoint(ctx, new.Endpoint)
|
||||
req.NoError(err)
|
||||
req.Equal(new.ID, fetched.ID)
|
||||
req.Equal(new.Endpoint, fetched.Endpoint)
|
||||
req.NotNil(fetched.CreatedAt)
|
||||
req.Nil(fetched.UpdatedAt)
|
||||
req.Nil(fetched.DeletedAt)
|
||||
})
|
||||
|
||||
t.Run("update", func(t *testing.T) {
|
||||
req := require.New(t)
|
||||
req.NoError(s.TruncateApigwRoutes(ctx))
|
||||
req.NoError(s.UpdateApigwRoute(ctx, new))
|
||||
})
|
||||
|
||||
t.Run("search", func(t *testing.T) {
|
||||
req := require.New(t)
|
||||
req.NoError(s.TruncateApigwRoutes(ctx))
|
||||
req.NoError(s.CreateApigwRoute(ctx,
|
||||
new,
|
||||
))
|
||||
|
||||
set, _, err := s.SearchApigwRoutes(ctx, types.ApigwRouteFilter{})
|
||||
req.NoError(err)
|
||||
req.Len(set, 1)
|
||||
})
|
||||
|
||||
t.Run("search only disabled", func(t *testing.T) {
|
||||
req := require.New(t)
|
||||
req.NoError(s.TruncateApigwRoutes(ctx))
|
||||
req.NoError(s.CreateApigwRoute(ctx,
|
||||
disabled,
|
||||
))
|
||||
|
||||
set, _, err := s.SearchApigwRoutes(ctx, types.ApigwRouteFilter{
|
||||
Disabled: filter.StateExclusive,
|
||||
})
|
||||
|
||||
req.NoError(err)
|
||||
req.Len(set, 1)
|
||||
req.Equal(set[0].ID, disabled.ID)
|
||||
})
|
||||
|
||||
t.Run("search enabled and disabled", func(t *testing.T) {
|
||||
req := require.New(t)
|
||||
req.NoError(s.TruncateApigwRoutes(ctx))
|
||||
req.NoError(s.CreateApigwRoute(ctx,
|
||||
new,
|
||||
disabled,
|
||||
))
|
||||
|
||||
set, _, err := s.SearchApigwRoutes(ctx, types.ApigwRouteFilter{
|
||||
Disabled: filter.StateInclusive,
|
||||
})
|
||||
|
||||
req.NoError(err)
|
||||
req.Len(set, 2)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user