Skip to content

Commit a8c9704

Browse files
author
Davor Gajic
committed
fix the db tests
1 parent 1061be2 commit a8c9704

File tree

6 files changed

+28
-54
lines changed

6 files changed

+28
-54
lines changed

create/application.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ type workerJob struct {
7777
}
7878

7979
type scheduledJob struct {
80-
Command string `help:"Command to execute to start the scheduled job." placeholder:"\"bundle exec sidekiq\""`
80+
Command string `help:"Command to execute to start the scheduled job." placeholder:"\"bundle exec rails runner\""`
8181
Name string `help:"Name of the scheduled job job to add." placeholder:"scheduled-1"`
82-
Size *string `help:"Size of the scheduled (defaults to \"${app_default_size}\")." placeholder:"${app_default_size}"`
82+
Size *string `help:"Size (resources) of the scheduled job (defaults to \"${app_default_size}\")." placeholder:"${app_default_size}"`
8383
Schedule string `help:"Cron notation string for the scheduled job (defaults to \"* * * * *\")." placeholder:"* * * * *"`
8484
}
8585

@@ -312,6 +312,7 @@ func (app *applicationCmd) config() apps.Config {
312312
Name: app.ScheduledJob.Name,
313313
Command: app.ScheduledJob.Command,
314314
},
315+
Schedule: app.ScheduledJob.Schedule,
315316
}
316317
if app.ScheduledJob.Size != nil {
317318
scheduledJob.Size = ptr.To(apps.ApplicationSize(*app.ScheduledJob.Size))

create/mysql_test.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package create
33
import (
44
"context"
55
"errors"
6-
"reflect"
76
"testing"
87
"time"
98

@@ -114,17 +113,7 @@ func TestMySQL(t *testing.T) {
114113
return
115114
}
116115

117-
// we set defaults for the slices
118-
if tt.want.AllowedCIDRs == nil {
119-
tt.want.AllowedCIDRs = []meta.IPv4CIDR{}
120-
}
121-
if tt.want.SSHKeys == nil {
122-
tt.want.SSHKeys = []storage.SSHKey{}
123-
}
124-
125-
if !reflect.DeepEqual(created.Spec.ForProvider, tt.want) {
126-
t.Fatalf("expected mysql.Spec.ForProvider = %+v, got: %+v", created.Spec.ForProvider, tt.want)
127-
}
116+
require.Equal(t, tt.want, created.Spec.ForProvider)
128117
})
129118
}
130119
}

create/postgres_test.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package create
33
import (
44
"context"
55
"errors"
6-
"reflect"
76
"testing"
87
"time"
98

@@ -94,17 +93,7 @@ func TestPostgres(t *testing.T) {
9493
return
9594
}
9695

97-
// we set defaults for the slices
98-
if tt.want.AllowedCIDRs == nil {
99-
tt.want.AllowedCIDRs = []meta.IPv4CIDR{}
100-
}
101-
if tt.want.SSHKeys == nil {
102-
tt.want.SSHKeys = []storage.SSHKey{}
103-
}
104-
105-
if !reflect.DeepEqual(created.Spec.ForProvider, tt.want) {
106-
t.Fatalf("expected postgres.Spec.ForProvider = %+v, got: %+v", created.Spec.ForProvider, tt.want)
107-
}
96+
require.Equal(t, tt.want, created.Spec.ForProvider)
10897
})
10998
}
11099
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ require (
2626
github.com/mattn/go-isatty v0.0.20
2727
github.com/moby/moby v27.1.1+incompatible
2828
github.com/moby/term v0.5.0
29-
github.com/ninech/apis v0.0.0-20250304143335-386c5bf8bc63
29+
github.com/ninech/apis v0.0.0-20250304140759-2e6d16e9749f
3030
github.com/posener/complete v1.2.3
3131
github.com/prometheus/common v0.55.0
3232
github.com/stretchr/testify v1.9.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,8 @@ github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+
597597
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
598598
github.com/ninech/apis v0.0.0-20250120083942-90d315ad8c32 h1:0XaOKTYVCIVd+oqG+7Km9j2/hVqkB4U7ySyEw15KvF0=
599599
github.com/ninech/apis v0.0.0-20250120083942-90d315ad8c32/go.mod h1:6srtlYi3nj8GRxQkbhvSbanIBc9vsoPLFOp5VQzNNhM=
600+
github.com/ninech/apis v0.0.0-20250304140759-2e6d16e9749f h1:3RXpRcPZKkw2rE7TyuFk8e+tWr8Mhl8bZqTDFm0ybWM=
601+
github.com/ninech/apis v0.0.0-20250304140759-2e6d16e9749f/go.mod h1:6srtlYi3nj8GRxQkbhvSbanIBc9vsoPLFOp5VQzNNhM=
600602
github.com/ninech/apis v0.0.0-20250304143335-386c5bf8bc63 h1:B8UqsTldPq5j2kLrkOsi++2jd1b5hk/O+yVrlR+AnVY=
601603
github.com/ninech/apis v0.0.0-20250304143335-386c5bf8bc63/go.mod h1:6srtlYi3nj8GRxQkbhvSbanIBc9vsoPLFOp5VQzNNhM=
602604
github.com/ninech/apis v0.0.0-20250305125840-3bc1e01edb09 h1:vihjujYXJAgRSa5VQgtpVkWNRcd3DccVbUn6PliMrgQ=

update/application.go

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ type workerJob struct {
9494
}
9595

9696
type scheduledJob struct {
97-
Command *string `help:"Command to execute to start the scheduled job." placeholder:"\"bundle exec sidekiq\""`
97+
Command *string `help:"Command to execute to start the scheduled job." placeholder:"\"bundle exec rails runner\""`
9898
Name *string `help:"Name of the scheduled job job to add." placeholder:"scheduled-1"`
99-
Size *string `help:"Size of the scheduled (defaults to \"${app_default_size}\")." placeholder:"${app_default_size}"`
99+
Size *string `help:"Size (resources) of the scheduled job (defaults to \"${app_default_size}\")." placeholder:"${app_default_size}"`
100100
Schedule *string `help:"Cron notation string for the scheduled job (defaults to \"* * * * *\")." placeholder:"* * * * *"`
101101
}
102102

@@ -312,29 +312,26 @@ func (job workerJob) applyUpdates(cfg *apps.Config) {
312312
if job.Name == nil {
313313
return
314314
}
315-
found := false
316315
for i := range cfg.WorkerJobs {
317316
if cfg.WorkerJobs[i].Name == *job.Name {
318-
found = true
319317
if job.Command != nil {
320318
cfg.WorkerJobs[i].Command = *job.Command
321319
}
322320
if job.Size != nil {
323321
cfg.WorkerJobs[i].Size = ptr.To(apps.ApplicationSize(*job.Size))
324322
}
323+
return
325324
}
326325
}
327326

328-
if !found {
329-
newJob := apps.WorkerJob{Job: apps.Job{Name: *job.Name}}
330-
if job.Command != nil {
331-
newJob.Command = *job.Command
332-
}
333-
if job.Size != nil {
334-
newJob.Size = ptr.To(apps.ApplicationSize(*job.Size))
335-
}
336-
cfg.WorkerJobs = append(cfg.WorkerJobs, newJob)
327+
newJob := apps.WorkerJob{Job: apps.Job{Name: *job.Name}}
328+
if job.Command != nil {
329+
newJob.Command = *job.Command
330+
}
331+
if job.Size != nil {
332+
newJob.Size = ptr.To(apps.ApplicationSize(*job.Size))
337333
}
334+
cfg.WorkerJobs = append(cfg.WorkerJobs, newJob)
338335
}
339336

340337
func deleteWorkerJob(name string, cfg *apps.Config) {
@@ -352,16 +349,13 @@ func deleteWorkerJob(name string, cfg *apps.Config) {
352349
}
353350

354351
func (job scheduledJob) applyUpdates(cfg *apps.Config) {
355-
if (job.Command != nil || job.Size != nil) && job.Name == nil {
356-
format.PrintWarningf("you need to pass a job name to update the command or size\n")
357-
}
358352
if job.Name == nil {
353+
format.PrintWarningf("you need to pass a job name to update the command, schedule or size\n")
359354
return
360355
}
361-
found := false
356+
362357
for i := range cfg.ScheduledJobs {
363358
if cfg.ScheduledJobs[i].Name == *job.Name {
364-
found = true
365359
if job.Command != nil {
366360
cfg.ScheduledJobs[i].Command = *job.Command
367361
}
@@ -371,19 +365,18 @@ func (job scheduledJob) applyUpdates(cfg *apps.Config) {
371365
if job.Schedule != nil {
372366
cfg.ScheduledJobs[i].Schedule = *job.Schedule
373367
}
368+
return
374369
}
375370
}
376371

377-
if !found {
378-
newJob := apps.ScheduledJob{Job: apps.Job{Name: *job.Name}}
379-
if job.Command != nil {
380-
newJob.Command = *job.Command
381-
}
382-
if job.Size != nil {
383-
newJob.Size = ptr.To(apps.ApplicationSize(*job.Size))
384-
}
385-
cfg.ScheduledJobs = append(cfg.ScheduledJobs, newJob)
372+
newJob := apps.ScheduledJob{Job: apps.Job{Name: *job.Name}}
373+
if job.Command != nil {
374+
newJob.Command = *job.Command
375+
}
376+
if job.Size != nil {
377+
newJob.Size = ptr.To(apps.ApplicationSize(*job.Size))
386378
}
379+
cfg.ScheduledJobs = append(cfg.ScheduledJobs, newJob)
387380
}
388381

389382
func deleteScheduledJob(name string, cfg *apps.Config) {

0 commit comments

Comments
 (0)