Skip to content

Commit 8e6bb4f

Browse files
added pointers in task implementation
1 parent 23cbfa8 commit 8e6bb4f

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

v2/arangodb/tasks_impl.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,36 @@ type taskResponse struct {
5858
func newTask(client *client, resp *taskResponse) Task {
5959
return &task{
6060
client: client,
61-
id: resp.ID,
62-
name: resp.Name,
63-
command: resp.Command,
61+
id: &resp.ID,
62+
name: &resp.Name,
63+
command: &resp.Command,
6464
params: resp.Params,
65-
period: resp.Period,
66-
offset: resp.Offset,
65+
period: &resp.Period,
66+
offset: &resp.Offset,
6767
}
6868
}
6969

7070
type task struct {
7171
client *client
72-
id string
73-
name string
74-
command string
72+
id *string
73+
name *string
74+
command *string
7575
params json.RawMessage
76-
period int64
77-
offset float64
76+
period *int64
77+
offset *float64
7878
}
7979

8080
// Task interface implementation for the task struct.
8181
func (t *task) ID() *string {
82-
return &t.id
82+
return t.id
8383
}
8484

8585
func (t *task) Name() *string {
86-
return &t.name
86+
return t.name
8787
}
8888

8989
func (t *task) Command() *string {
90-
return &t.command
90+
return t.command
9191
}
9292

9393
func (t *task) Params(result interface{}) error {
@@ -98,11 +98,11 @@ func (t *task) Params(result interface{}) error {
9898
}
9999

100100
func (t *task) Period() *int64 {
101-
return &t.period
101+
return t.period
102102
}
103103

104104
func (t *task) Offset() *float64 {
105-
return &t.offset
105+
return t.offset
106106
}
107107

108108
// Tasks retrieves all tasks from the specified database.
@@ -178,28 +178,28 @@ func (c *clientTask) CreateTask(ctx context.Context, databaseName string, option
178178
}
179179
// Prepare the request body
180180
createRequest := struct {
181-
ID string `json:"id,omitempty"`
182-
Name string `json:"name,omitempty"`
183-
Command string `json:"command,omitempty"`
181+
ID *string `json:"id,omitempty"`
182+
Name *string `json:"name,omitempty"`
183+
Command *string `json:"command,omitempty"`
184184
Params json.RawMessage `json:"params,omitempty"`
185-
Period int64 `json:"period,omitempty"`
186-
Offset float64 `json:"offset,omitempty"`
185+
Period *int64 `json:"period,omitempty"`
186+
Offset *float64 `json:"offset,omitempty"`
187187
}{}
188188

189189
if options.ID != nil {
190-
createRequest.ID = *options.ID
190+
createRequest.ID = options.ID
191191
}
192192
if options.Name != nil {
193-
createRequest.Name = *options.Name
193+
createRequest.Name = options.Name
194194
}
195195
if options.Command != nil {
196-
createRequest.Command = *options.Command
196+
createRequest.Command = options.Command
197197
}
198198
if options.Period != nil {
199-
createRequest.Period = *options.Period
199+
createRequest.Period = options.Period
200200
}
201201
if options.Offset != nil {
202-
createRequest.Offset = *options.Offset
202+
createRequest.Offset = options.Offset
203203
}
204204

205205
if options.Params != nil {

v2/tests/tasks_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ func Test_CreateNewTask(t *testing.T) {
3838
Wrap(t, func(t *testing.T, client arangodb.Client) {
3939
dbName := "_system"
4040
testCases := map[string]*arangodb.TaskOptions{
41-
"taskWIthParams": {
42-
Name: utils.NewType("taskWIthParams"),
41+
"taskWithParams": {
42+
Name: utils.NewType("taskWithParams"),
4343
Command: utils.NewType("(function(params) { require('@arangodb').print(params); })(params)"),
4444
Period: utils.NewType(int64(2)),
4545
Params: map[string]interface{}{
4646
"test": "hello",
4747
},
4848
},
49-
"taskWIthOutParams": {
50-
Name: utils.NewType("taskWIthOutParams"),
49+
"taskWithoutParams": {
50+
Name: utils.NewType("taskWithoutParams"),
5151
Command: utils.NewType("(function() { require('@arangodb').print('Hello'); })()"),
5252
Period: utils.NewType(int64(2)),
5353
},
@@ -108,11 +108,11 @@ func Test_ValidationsForCreateNewTask(t *testing.T) {
108108
Wrap(t, func(t *testing.T, client arangodb.Client) {
109109
dbName := "_system"
110110
testCases := map[string]*arangodb.TaskOptions{
111-
"taskWIthOutCommand": {
112-
Name: utils.NewType("taskWIthOutCommand"),
111+
"taskWithoutCommand": {
112+
Name: utils.NewType("taskWithoutCommand"),
113113
Period: utils.NewType(int64(2)),
114114
},
115-
"taskWIthOutPeriod": nil,
115+
"taskWithoutPeriod": nil,
116116
}
117117

118118
for name, options := range testCases {

0 commit comments

Comments
 (0)