@@ -19,12 +19,15 @@ package tasks
19
19
20
20
import (
21
21
"fmt"
22
+ "testing"
23
+ "time"
24
+
25
+ "github.com/apache/incubator-devlake/core/models/domainlayer/devops"
22
26
"github.com/apache/incubator-devlake/core/models/domainlayer/didgen"
23
27
"github.com/apache/incubator-devlake/core/plugin"
24
28
mockplugin "github.com/apache/incubator-devlake/mocks/core/plugin"
25
29
"github.com/apache/incubator-devlake/plugins/github/models"
26
30
"github.com/stretchr/testify/assert"
27
- "testing"
28
31
)
29
32
30
33
func GenJobIDWithReflect (jobIdGen * didgen.DomainIdGenerator ) {
@@ -63,3 +66,65 @@ func BenchmarkGenJobID(b *testing.B) {
63
66
}
64
67
//BenchmarkGenJobID-8 11078593 99.43 ns/op
65
68
}
69
+
70
+ func TestConvertJobs_SkipNoStartedAt (t * testing.T ) {
71
+ job := & models.GithubJob {
72
+ ID : 123 ,
73
+ RunID : 456 ,
74
+ Name : "test-job" ,
75
+ StartedAt : nil ,
76
+ }
77
+
78
+ convert := func (inputRow interface {}) ([]interface {}, error ) {
79
+ line := inputRow .(* models.GithubJob )
80
+ if line .StartedAt == nil {
81
+ return nil , nil
82
+ }
83
+ createdAt := * line .StartedAt
84
+ domainJob := & devops.CICDTask {
85
+ Name : line .Name ,
86
+ TaskDatesInfo : devops.TaskDatesInfo {
87
+ CreatedDate : createdAt ,
88
+ StartedDate : line .StartedAt ,
89
+ FinishedDate : line .CompletedAt ,
90
+ },
91
+ }
92
+ return []interface {}{domainJob }, nil
93
+ }
94
+
95
+ result , err := convert (job )
96
+ assert .Nil (t , err )
97
+ assert .Nil (t , result )
98
+ }
99
+
100
+ func TestConvertJobs_WithStartedAt (t * testing.T ) {
101
+ now := time .Now ()
102
+ job := & models.GithubJob {
103
+ ID : 123 ,
104
+ RunID : 456 ,
105
+ Name : "test-job" ,
106
+ StartedAt : & now ,
107
+ }
108
+
109
+ convert := func (inputRow interface {}) ([]interface {}, error ) {
110
+ line := inputRow .(* models.GithubJob )
111
+ if line .StartedAt == nil {
112
+ return nil , nil
113
+ }
114
+ createdAt := * line .StartedAt
115
+ domainJob := & devops.CICDTask {
116
+ Name : line .Name ,
117
+ TaskDatesInfo : devops.TaskDatesInfo {
118
+ CreatedDate : createdAt ,
119
+ StartedDate : line .StartedAt ,
120
+ FinishedDate : line .CompletedAt ,
121
+ },
122
+ }
123
+ return []interface {}{domainJob }, nil
124
+ }
125
+
126
+ result , err := convert (job )
127
+ assert .Nil (t , err )
128
+ assert .NotNil (t , result )
129
+ assert .Equal (t , "test-job" , result [0 ].(* devops.CICDTask ).Name )
130
+ }
0 commit comments