Merged in feature/serviceconfig-integration (pull request #38)
DRAFT PR : WIP working through ideas for integration * movearound * attempttwo * openapi * further sanding * fix * start on tests * runthroughsingleconfig * somechanges * reflectissue * removeerrs * mostlyremovepanic * removeenv * noncfgtests * go * repo * fix service config test * add PWD to all * test fix * fix lint * todo for later * passingunittests * alltests * testlogger * testloggername * clean
This commit is contained in:
@@ -13,7 +13,7 @@ func (s *Service) Create(ctx context.Context, name string) (uuid.UUID, error) {
|
||||
return uuid.Nil, err
|
||||
}
|
||||
|
||||
id, err := s.db.Queries.CreateClient(ctx, name)
|
||||
id, err := s.cfg.GetDBQueries().CreateClient(ctx, name)
|
||||
if err != nil {
|
||||
return uuid.Nil, err
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -19,13 +20,11 @@ func TestCreate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := client.New(db)
|
||||
svc := client.New(cfg)
|
||||
|
||||
name := "client_name"
|
||||
aid := uuid.New()
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func (s *Service) Get(ctx context.Context, id uuid.UUID) (*Client, error) {
|
||||
client, err := s.db.Queries.GetClient(ctx, database.MustToDBUUID(id))
|
||||
client, err := s.cfg.GetDBQueries().GetClient(ctx, database.MustToDBUUID(id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -20,13 +21,11 @@ func TestGet(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := client.New(db)
|
||||
svc := client.New(cfg)
|
||||
|
||||
id := uuid.New()
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package client
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
@@ -70,11 +70,11 @@ func normalizeName(name *string) error {
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
db *database.Connection
|
||||
cfg serviceconfig.ConfigProvider
|
||||
}
|
||||
|
||||
func New(db *database.Connection) *Service {
|
||||
func New(cfg serviceconfig.ConfigProvider) *Service {
|
||||
return &Service{
|
||||
db,
|
||||
cfg,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package client_test
|
||||
|
||||
import (
|
||||
"queryorchestration/internal/client"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
@@ -15,12 +15,10 @@ func TestService(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := client.New(db)
|
||||
svc := client.New(cfg)
|
||||
assert.NotNil(t, svc)
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ func (s *Service) Update(ctx context.Context, entity *Update) error {
|
||||
}
|
||||
|
||||
func (s *Service) submitUpdate(ctx context.Context, entity *Update) error {
|
||||
return database.ExecuteTransaction(ctx, s.db, func(ctx context.Context, q *repository.Queries) error {
|
||||
return s.cfg.ExecuteDBTransaction(ctx, func(ctx context.Context, q *repository.Queries) error {
|
||||
id := database.MustToDBUUID(entity.ID)
|
||||
|
||||
if entity.Name != nil {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"queryorchestration/internal/database"
|
||||
"queryorchestration/internal/database/repository"
|
||||
"queryorchestration/internal/serviceconfig"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -18,13 +19,11 @@ func TestUpdate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := New(db)
|
||||
svc := New(cfg)
|
||||
|
||||
c := Client{
|
||||
ID: uuid.New(),
|
||||
@@ -119,13 +118,11 @@ func TestSubmitUpdate(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
queries := repository.New(pool)
|
||||
db := &database.Connection{
|
||||
Queries: queries,
|
||||
Pool: pool,
|
||||
}
|
||||
cfg := &serviceconfig.BaseConfig{}
|
||||
cfg.DBPool = pool
|
||||
cfg.DBQueries = repository.New(pool)
|
||||
|
||||
svc := New(db)
|
||||
svc := New(cfg)
|
||||
|
||||
c := Client{
|
||||
ID: uuid.New(),
|
||||
|
||||
Reference in New Issue
Block a user