-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathexecutor_test.go
More file actions
86 lines (79 loc) · 1.56 KB
/
executor_test.go
File metadata and controls
86 lines (79 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package executor_test
import (
"context"
"reflect"
"testing"
"time"
executor "github.com/gopherdojo/dojo5/kadai3-2/nagaa052/pkg/executor"
)
func TestNew(t *testing.T) {
type args struct {
maxWorkers int
timeout time.Duration
}
tests := []struct {
name string
args args
want *executor.Executor
}{
{
name: "Success Test",
args: args{
maxWorkers: 4,
timeout: 2 * time.Second,
},
want: &executor.Executor{
Timeout: 2 * time.Second,
Jobs: make([]*executor.Job, 0),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := executor.New(tt.args.maxWorkers, tt.args.timeout); !reflect.DeepEqual(got, tt.want) {
t.Errorf("New() = %v, want %v", got, tt.want)
}
})
}
}
type mockPayload struct{}
func (p *mockPayload) Execute(context.Context) error {
return nil
}
func TestExecutor_Start(t *testing.T) {
type fields struct {
Timeout time.Duration
Jobs []*executor.Job
}
tests := []struct {
name string
fields fields
wantErr bool
}{
{
name: "Success Test",
fields: fields{
Timeout: 2 * time.Second,
Jobs: []*executor.Job{
&executor.Job{
&mockPayload{},
},
&executor.Job{
&mockPayload{},
},
},
},
wantErr: false,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
ex := &executor.Executor{tt.fields.Timeout, tt.fields.Jobs}
if err := ex.Start(); (err != nil) != tt.wantErr {
t.Errorf("Executor.Start() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}