Skip to content

Commit

Permalink
fix get and list scheduler test
Browse files Browse the repository at this point in the history
  • Loading branch information
manuellysuzik committed May 16, 2023
1 parent fa031c3 commit 7699a28
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 5 deletions.
3 changes: 3 additions & 0 deletions internal/api/handlers/requestadapters/schedulers.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ func FromApiNewSchedulerVersionRequestToEntity(request *api.NewSchedulerVersionR

func FromEntitySchedulerToResponse(entity *entities.Scheduler) (*api.Scheduler, error) {
forwarders, err := fromEntityForwardersToResponse(entity.Forwarders)
if err != nil {
return nil, err
}
annotations, err := fromEntityAnnotationsToResponse(entity.Annotations)
if err != nil {
return nil, err
Expand Down
10 changes: 9 additions & 1 deletion internal/api/handlers/schedulers_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ func TestGetScheduler(t *testing.T) {
},
},
},
Annotations: []*entities.Annotations{},
}

schedulerCache.EXPECT().GetScheduler(gomock.Any(), gomock.Any()).Return(scheduler, nil)
Expand Down Expand Up @@ -539,6 +540,7 @@ func TestCreateScheduler(t *testing.T) {
},
},
},
Annotations: []*entities.Annotations{entities.NewAnnotations("annotation", "option")},
}

schedulerStorage.EXPECT().CreateScheduler(gomock.Any(), gomock.Any()).Do(
Expand All @@ -556,6 +558,10 @@ func TestCreateScheduler(t *testing.T) {
assert.Equal(t, scheduler.Forwarders[i].Address, forwarder.Address)
assert.Equal(t, scheduler.Forwarders[i].Options.Timeout, forwarder.Options.Timeout)
}
for i, annotation := range arg.Annotations {
assert.Equal(t, scheduler.Annotations[i].Name, annotation.Name)
assert.Equal(t, scheduler.Annotations[i].Opt, annotation.Opt)
}
},
).Return(nil)
operationManager.EXPECT().CreateOperation(gomock.Any(), scheduler.Name, gomock.Any()).Return(&operation.Operation{ID: "id-1"}, nil)
Expand Down Expand Up @@ -1235,6 +1241,7 @@ func newValidScheduler() *entities.Scheduler {
},
}
forwarders := []*forwarder.Forwarder{fwd}
annotations := []*entities.Annotations{entities.NewAnnotations("imageregistry", "https://hub.docker.com/")}

return &entities.Scheduler{
Name: "scheduler-name-1",
Expand Down Expand Up @@ -1272,6 +1279,7 @@ func newValidScheduler() *entities.Scheduler {
Start: 40000,
End: 60000,
},
Forwarders: forwarders,
Forwarders: forwarders,
Annotations: annotations,
}
}
2 changes: 1 addition & 1 deletion internal/core/entities/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type Scheduler struct {
CreatedAt time.Time
MaxSurge string `validate:"required,max_surge"`
Forwarders []*forwarder.Forwarder `validate:"dive"`
Annotations []*Annotations `validate:"optional"`
Annotations []*Annotations
}

type Annotations struct {
Expand Down
4 changes: 3 additions & 1 deletion pkg/api/v1/messages.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions proto/api/v1/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ message Container {
}
// Annotation should add a annotation to scheduler
message Annotation{
// name of the annotation
string name = 1;
// required annotation value or option
string value = 2;
}

Expand Down
6 changes: 4 additions & 2 deletions proto/apidocs.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -893,10 +893,12 @@
"type": "object",
"properties": {
"name": {
"type": "string"
"type": "string",
"title": "name of the annotation"
},
"value": {
"type": "string"
"type": "string",
"title": "required annotation value or option"
}
},
"title": "Annotation should add a annotation to scheduler"
Expand Down

0 comments on commit 7699a28

Please sign in to comment.