Skip to content

Commit 0588a22

Browse files
committed
Refactor and update mock implementations; enhance error handling and response structures
Signed-off-by: rafi <refaei.shikho@hotmail.com>
1 parent 3c3ecbf commit 0588a22

13 files changed

Lines changed: 684 additions & 407 deletions

controllers/org_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (controller *OrgController) Create(ctx shared.Context) error {
6565
settings = shared.InstanceSettings{}
6666
}
6767
if settings.SingleOrganizationMode {
68-
return echo.NewHTTPError(400, "creating organizations is not allowed in single organization mode")
68+
return echo.NewHTTPError(403, "creating organizations is not allowed in single organization mode")
6969
}
7070

7171
var req dtos.OrgCreateRequest

controllers/org_controller_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,7 @@ func TestCreate(t *testing.T) {
257257
e := echo.New()
258258
ctx := e.NewContext(req, httptest.NewRecorder())
259259

260-
h := NewOrganizationController(nil, nil, nil, nil, nil)
261-
260+
h := NewOrganizationController(nil, nil, nil, nil, nil, nil)
262261
err := h.Create(ctx)
263262
if err == nil {
264263
t.Fail()
@@ -272,7 +271,7 @@ func TestCreate(t *testing.T) {
272271

273272
shared.SetOrg(ctx, models.Org{Name: "fantasy", Slug: "fantasy"})
274273

275-
h := NewOrganizationController(nil, nil, nil, nil, nil)
274+
h := NewOrganizationController(nil, nil, nil, nil, nil, nil)
276275

277276
err := h.Create(ctx)
278277
if err == nil {
@@ -286,7 +285,7 @@ func TestCreate(t *testing.T) {
286285
e := echo.New()
287286
ctx := e.NewContext(req, httptest.NewRecorder())
288287

289-
h := NewOrganizationController(nil, nil, nil, nil, nil)
288+
h := NewOrganizationController(nil, nil, nil, nil, nil, nil)
290289

291290
err := h.Create(ctx)
292291
if err == nil {

daemons/daemon.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,16 @@ func (runner *DaemonRunner) SetInstanceSettings(ctx context.Context) error {
7575
return runner.configService.SetJSONConfig(ctx, "instance_settings", shared.InstanceSettings{
7676
SingleOrganizationMode: true,
7777
})
78+
} else {
79+
return runner.configService.SetJSONConfig(ctx, "instance_settings", shared.InstanceSettings{
80+
SingleOrganizationMode: false,
81+
})
7882
}
79-
return nil
8083
}
8184

8285
func (runner *DaemonRunner) runDaemons() {
8386
ctx := context.Background()
8487

85-
if err := runner.SetInstanceSettings(ctx); err != nil {
86-
slog.Error("could not set instance settings", "err", err)
87-
}
88-
8988
if err := runner.maybeRunAndMark("maintain.cleanup", func() error {
9089
return runner.CleanupOrphanedRecords(ctx)
9190
}); err != nil {

daemons/providers.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ func (runner *DaemonRunner) Start(ctx context.Context) {
152152
}
153153

154154
func (runner *DaemonRunner) tick() {
155+
if err := runner.SetInstanceSettings(context.Background()); err != nil {
156+
slog.Error("could not set instance settings", "err", err)
157+
}
158+
155159
if runner.leaderElector.IsLeader() {
156160
slog.Info("this instance is the leader - running background jobs")
157161
runner.runDaemons()

mocks/mock_AffectedComponentRepository.go

Lines changed: 0 additions & 131 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)