@@ -93,6 +93,117 @@ func TestParseTasksRecievesMalformedJSONBlob(t *testing.T) {
9393 require .Error (t , err )
9494}
9595
96+ var getMetricTestCases = []struct {
97+ task * Task
98+ prefix string
99+ expectedTaskMetric string
100+ }{
101+ {
102+ task : & Task {
103+ TaskStatus : "task_running" ,
104+ AppID : "com.example.domain.context/app-name" ,
105+ },
106+ prefix : "com.example." ,
107+ expectedTaskMetric : "domain.context.app-name.task_running" ,
108+ },
109+ {
110+ task : & Task {
111+ TaskStatus : "task_running" ,
112+ AppID : "/com.example.domain.context/app-name" ,
113+ },
114+ prefix : "com.example." ,
115+ expectedTaskMetric : "domain.context.app-name.task_running" ,
116+ },
117+ {
118+ task : & Task {
119+ TaskStatus : "task_running" ,
120+ AppID : "com.example.domain.context/app-name" ,
121+ },
122+ prefix : "" ,
123+ expectedTaskMetric : "com.example.domain.context.app-name.task_running" ,
124+ },
125+ {
126+ task : & Task {
127+ TaskStatus : "task_running" ,
128+ AppID : "com.example.domain.context/group/app-name" ,
129+ },
130+ prefix : "com.example." ,
131+ expectedTaskMetric : "domain.context.group.app-name.task_running" ,
132+ },
133+ {
134+ task : & Task {
135+ TaskStatus : "task_staging" ,
136+ AppID : "com.example.domain.context/group/app-name" ,
137+ },
138+ prefix : "com.example." ,
139+ expectedTaskMetric : "domain.context.group.app-name.task_staging" ,
140+ },
141+ {
142+ task : & Task {
143+ TaskStatus : "task_staging" ,
144+ AppID : "com.example.domain.context/group/nested-group/app-name" ,
145+ },
146+ prefix : "com.example." ,
147+ expectedTaskMetric : "domain.context.group.nested-group.app-name.task_staging" ,
148+ },
149+ {
150+ task : & Task {
151+ TaskStatus : "task_running" ,
152+ AppID : "app-name" ,
153+ },
154+ prefix : "com.example." ,
155+ expectedTaskMetric : "app-name.task_running" ,
156+ },
157+ {
158+ task : & Task {
159+ TaskStatus : "task_running" ,
160+ AppID : "app-name" ,
161+ },
162+ prefix : "" ,
163+ expectedTaskMetric : "app-name.task_running" ,
164+ },
165+ {
166+ task : & Task {
167+ TaskStatus : "task_running" ,
168+ AppID : "com.example.domain.context/app-name" ,
169+ },
170+ prefix : "" ,
171+ expectedTaskMetric : "com.example.domain.context.app-name.task_running" ,
172+ },
173+ {
174+ task : & Task {
175+ TaskStatus : "task_running" ,
176+ AppID : "" ,
177+ },
178+ prefix : "com.example." ,
179+ expectedTaskMetric : "task_running" ,
180+ },
181+ {
182+ task : & Task {
183+ TaskStatus : "" ,
184+ AppID : "com.example.domain.context/app-name" ,
185+ },
186+ prefix : "com.example." ,
187+ expectedTaskMetric : "domain.context.app-name" ,
188+ },
189+ {
190+ task : & Task {
191+ TaskStatus : "" ,
192+ AppID : "" ,
193+ },
194+ prefix : "com.example." ,
195+ expectedTaskMetric : "" ,
196+ },
197+ }
198+
199+ func TestTaskGetMetricTestCases (t * testing.T ) {
200+ t .Parallel ()
201+ for _ , testCase := range getMetricTestCases {
202+ taskMetric := testCase .task .GetMetric (testCase .prefix )
203+ assert .Equal (t , testCase .expectedTaskMetric , taskMetric )
204+ }
205+ }
206+
96207var penalizeTestCases = []struct {
97208 app * App
98209 expectedApp * App
0 commit comments