Remove all system deps from compose
This commit is contained in:
@@ -22,8 +22,6 @@ import (
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/crusttech/crust/internal/store"
|
||||
|
||||
systemService "github.com/crusttech/crust/system/service"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -44,7 +42,6 @@ type (
|
||||
pageSvc PageService
|
||||
moduleSvc ModuleService
|
||||
recordSvc RecordService
|
||||
usr systemService.UserService
|
||||
|
||||
attachment repository.AttachmentRepository
|
||||
}
|
||||
@@ -75,7 +72,6 @@ func Attachment(store store.Store) AttachmentService {
|
||||
pageSvc: DefaultPage,
|
||||
moduleSvc: DefaultModule,
|
||||
recordSvc: DefaultRecord,
|
||||
usr: systemService.DefaultUser,
|
||||
}).With(context.Background())
|
||||
}
|
||||
|
||||
@@ -90,7 +86,6 @@ func (svc attachment) With(ctx context.Context) AttachmentService {
|
||||
pageSvc: svc.pageSvc.With(ctx),
|
||||
moduleSvc: svc.moduleSvc.With(ctx),
|
||||
recordSvc: svc.recordSvc.With(ctx),
|
||||
usr: systemService.User(ctx),
|
||||
store: svc.store,
|
||||
|
||||
attachment: repository.Attachment(ctx, db),
|
||||
|
||||
@@ -11,20 +11,13 @@ import (
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
systemTypes "github.com/crusttech/crust/system/types"
|
||||
)
|
||||
|
||||
func TestChart(t *testing.T) {
|
||||
ctx := context.WithValue(context.Background(), "testing", true)
|
||||
|
||||
user := &systemTypes.User{
|
||||
ID: 1337,
|
||||
Name: "John Crm Doe",
|
||||
Username: "johndoe",
|
||||
}
|
||||
|
||||
// Set Identity (required for permission checks).
|
||||
ctx = auth.SetIdentityToContext(ctx, user)
|
||||
ctx = auth.SetIdentityToContext(ctx, auth.NewIdentity(1337))
|
||||
|
||||
ns1, _ := createTestNamespaces(ctx, t)
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@ import (
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
systemMigrate "github.com/crusttech/crust/system/db"
|
||||
systemService "github.com/crusttech/crust/system/service"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -35,16 +33,11 @@ func TestMain(m *testing.M) {
|
||||
|
||||
factory.Database.Add("default", dsn)
|
||||
factory.Database.Add("compose", dsn)
|
||||
factory.Database.Add("system", dsn)
|
||||
|
||||
db := factory.Database.MustGet()
|
||||
db.Profiler = &factory.Database.ProfilerStdout
|
||||
|
||||
// migrate database schema
|
||||
if err := systemMigrate.Migrate(db); err != nil {
|
||||
fmt.Printf("Error running migrations: %+v\n", err)
|
||||
return
|
||||
}
|
||||
if err := composeMigrate.Migrate(db); err != nil {
|
||||
fmt.Printf("Error running migrations: %+v\n", err)
|
||||
return
|
||||
@@ -52,7 +45,7 @@ func TestMain(m *testing.M) {
|
||||
|
||||
// clean up tables
|
||||
{
|
||||
for _, name := range []string{"compose_chart", "compose_trigger", "compose_module", "compose_module_form", "compose_record", "compose_record_value", "compose_page", "sys_user"} {
|
||||
for _, name := range []string{"compose_chart", "compose_trigger", "compose_module", "compose_module_form", "compose_record", "compose_record_value", "compose_page"} {
|
||||
_, err := db.Exec("truncate " + name)
|
||||
if err != nil {
|
||||
panic("Error when clearing " + name + ": " + err.Error())
|
||||
@@ -62,7 +55,6 @@ func TestMain(m *testing.M) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
systemService.Init(ctx)
|
||||
Init(ctx)
|
||||
|
||||
os.Exit(m.Run())
|
||||
|
||||
@@ -9,20 +9,13 @@ import (
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
systemTypes "github.com/crusttech/crust/system/types"
|
||||
)
|
||||
|
||||
func TestModule(t *testing.T) {
|
||||
ctx := context.WithValue(context.Background(), "testing", true)
|
||||
|
||||
user := &systemTypes.User{
|
||||
ID: 1337,
|
||||
Name: "John Crm Doe",
|
||||
Username: "johndoe",
|
||||
}
|
||||
|
||||
// Set Identity (required for permission checks).
|
||||
ctx = auth.SetIdentityToContext(ctx, user)
|
||||
ctx = auth.SetIdentityToContext(ctx, auth.NewIdentity(1337))
|
||||
|
||||
ns1, _ := createTestNamespaces(ctx, t)
|
||||
|
||||
|
||||
@@ -9,20 +9,13 @@ import (
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
systemTypes "github.com/crusttech/crust/system/types"
|
||||
)
|
||||
|
||||
func TestNamespace(t *testing.T) {
|
||||
ctx := context.WithValue(context.Background(), "testing", true)
|
||||
|
||||
user := &systemTypes.User{
|
||||
ID: 1337,
|
||||
Name: "John Crm Doe",
|
||||
Username: "johndoe",
|
||||
}
|
||||
|
||||
// Set Identity (required for permission checks).
|
||||
ctx = auth.SetIdentityToContext(ctx, user)
|
||||
ctx = auth.SetIdentityToContext(ctx, auth.NewIdentity(1337))
|
||||
|
||||
svc := Namespace().With(ctx)
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
@@ -12,15 +11,12 @@ import (
|
||||
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
"github.com/crusttech/crust/internal/mail"
|
||||
systemService "github.com/crusttech/crust/system/service"
|
||||
)
|
||||
|
||||
type (
|
||||
notification struct {
|
||||
ctx context.Context
|
||||
logger *zap.Logger
|
||||
|
||||
userSvc systemService.UserService
|
||||
}
|
||||
|
||||
NotificationService interface {
|
||||
@@ -34,8 +30,6 @@ type (
|
||||
func Notification() NotificationService {
|
||||
return (¬ification{
|
||||
logger: DefaultLogger.Named("notification"),
|
||||
|
||||
userSvc: systemService.DefaultUser,
|
||||
}).With(context.Background())
|
||||
}
|
||||
|
||||
@@ -43,8 +37,6 @@ func (svc notification) With(ctx context.Context) NotificationService {
|
||||
return ¬ification{
|
||||
ctx: ctx,
|
||||
logger: svc.logger,
|
||||
|
||||
userSvc: systemService.User(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,10 +66,6 @@ func (svc notification) AttachEmailRecipients(message *gomail.Message, field str
|
||||
return
|
||||
}
|
||||
|
||||
if recipients, err = svc.expandUserRefs(recipients); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for r, rcpt := range recipients {
|
||||
name, email = "", ""
|
||||
rcpt = strings.TrimSpace(rcpt)
|
||||
@@ -100,21 +88,3 @@ func (svc notification) AttachEmailRecipients(message *gomail.Message, field str
|
||||
message.SetHeader(field, recipients...)
|
||||
return
|
||||
}
|
||||
|
||||
// Expands references to users (strings as numeric uint64)
|
||||
//
|
||||
// This func is extracted to make testing/mocking mocking
|
||||
func (svc notification) expandUserRefs(recipients []string) ([]string, error) {
|
||||
for r, rcpt := range recipients {
|
||||
// First, get userID off the table
|
||||
if userID, _ := strconv.ParseUint(rcpt, 10, 64); userID > 0 {
|
||||
if user, err := svc.userSvc.FindByID(userID); err != nil {
|
||||
return nil, errors.Wrapf(err, "invalid recipient %d", userID)
|
||||
} else {
|
||||
recipients[r] = user.Email + " " + user.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return recipients, nil
|
||||
}
|
||||
|
||||
@@ -12,20 +12,13 @@ import (
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
systemTypes "github.com/crusttech/crust/system/types"
|
||||
)
|
||||
|
||||
func TestPage(t *testing.T) {
|
||||
ctx := context.WithValue(context.Background(), "testing", true)
|
||||
|
||||
user := &systemTypes.User{
|
||||
ID: 1337,
|
||||
Name: "John Crm Doe",
|
||||
Username: "johndoe",
|
||||
}
|
||||
|
||||
// Set Identity (required for permission checks).
|
||||
ctx = auth.SetIdentityToContext(ctx, user)
|
||||
// Set fake Identity (required for permission checks).
|
||||
ctx = auth.SetIdentityToContext(ctx, auth.NewIdentity(1337))
|
||||
|
||||
ns1, _ := createTestNamespaces(ctx, t)
|
||||
|
||||
|
||||
@@ -14,8 +14,6 @@ import (
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/crusttech/crust/internal/logger"
|
||||
|
||||
systemService "github.com/crusttech/crust/system/service"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -24,8 +22,7 @@ type (
|
||||
ctx context.Context
|
||||
logger *zap.Logger
|
||||
|
||||
ac recordAccessController
|
||||
userSvc systemService.UserService
|
||||
ac recordAccessController
|
||||
|
||||
recordRepo repository.RecordRepository
|
||||
moduleRepo repository.ModuleRepository
|
||||
@@ -58,9 +55,8 @@ type (
|
||||
|
||||
func Record() RecordService {
|
||||
return (&record{
|
||||
logger: DefaultLogger.Named("record"),
|
||||
ac: DefaultAccessControl,
|
||||
userSvc: systemService.DefaultUser,
|
||||
logger: DefaultLogger.Named("record"),
|
||||
ac: DefaultAccessControl,
|
||||
}).With(context.Background())
|
||||
}
|
||||
|
||||
@@ -71,8 +67,7 @@ func (svc record) With(ctx context.Context) RecordService {
|
||||
ctx: ctx,
|
||||
logger: svc.logger,
|
||||
|
||||
ac: svc.ac,
|
||||
userSvc: systemService.User(ctx),
|
||||
ac: svc.ac,
|
||||
|
||||
recordRepo: repository.Record(ctx, db),
|
||||
moduleRepo: repository.Module(ctx, db),
|
||||
|
||||
@@ -9,29 +9,16 @@ import (
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
systemService "github.com/crusttech/crust/system/service"
|
||||
systemTypes "github.com/crusttech/crust/system/types"
|
||||
)
|
||||
|
||||
func TestRecord(t *testing.T) {
|
||||
ctx := context.WithValue(context.Background(), "testing", true)
|
||||
|
||||
user := &systemTypes.User{
|
||||
ID: 1337,
|
||||
Username: "TestUser",
|
||||
}
|
||||
|
||||
ctx = auth.SetIdentityToContext(ctx, auth.NewIdentity(user.Identity()))
|
||||
ctx = auth.SetIdentityToContext(ctx, auth.NewIdentity(1337))
|
||||
|
||||
var err error
|
||||
ns1, ns2 := createTestNamespaces(ctx, t)
|
||||
|
||||
{
|
||||
userSvc := systemService.TestUser(t, ctx)
|
||||
_, err := userSvc.Create(user)
|
||||
test.NoError(t, err, "expected no error creating user, got %v", err)
|
||||
}
|
||||
|
||||
svc := Record().With(ctx)
|
||||
|
||||
module1 := &types.Module{
|
||||
|
||||
@@ -11,20 +11,13 @@ import (
|
||||
"github.com/crusttech/crust/compose/types"
|
||||
"github.com/crusttech/crust/internal/auth"
|
||||
"github.com/crusttech/crust/internal/test"
|
||||
systemTypes "github.com/crusttech/crust/system/types"
|
||||
)
|
||||
|
||||
func TestTrigger(t *testing.T) {
|
||||
ctx := context.WithValue(context.Background(), "testing", true)
|
||||
|
||||
user := &systemTypes.User{
|
||||
ID: 1337,
|
||||
Name: "John Crm Doe",
|
||||
Username: "johndoe",
|
||||
}
|
||||
|
||||
// Set Identity (required for permission checks).
|
||||
ctx = auth.SetIdentityToContext(ctx, user)
|
||||
ctx = auth.SetIdentityToContext(ctx, auth.NewIdentity(1337))
|
||||
|
||||
ns1, _ := createTestNamespaces(ctx, t)
|
||||
|
||||
|
||||
@@ -8,8 +8,6 @@ import (
|
||||
|
||||
func Init(ctx context.Context) error {
|
||||
err := service.Init(ctx)
|
||||
DefaultRole = service.DefaultRole
|
||||
// DefaultRules = service.DefaultRules
|
||||
DefaultUser = service.DefaultUser
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/crusttech/crust/system/internal/service"
|
||||
"github.com/crusttech/crust/system/types"
|
||||
)
|
||||
|
||||
type (
|
||||
RoleService interface {
|
||||
FindByID(roleID uint64) (*types.Role, error)
|
||||
Find(filter *types.RoleFilter) ([]*types.Role, error)
|
||||
}
|
||||
)
|
||||
|
||||
var DefaultRole = service.DefaultRole
|
||||
|
||||
func Role(ctx context.Context) RoleService {
|
||||
return DefaultRole.With(ctx)
|
||||
}
|
||||
|
||||
// Expose the full Role API for testing
|
||||
func TestRole(_ *testing.T, ctx context.Context) service.RoleService {
|
||||
return DefaultRole.With(ctx)
|
||||
}
|
||||
Reference in New Issue
Block a user