@@ -2,19 +2,23 @@ package net.leanix.githubagent.services
2
2
3
3
import io.mockk.every
4
4
import io.mockk.mockk
5
+ import io.mockk.slot
5
6
import io.mockk.verify
6
7
import net.leanix.githubagent.client.GitHubClient
7
8
import net.leanix.githubagent.dto.Account
8
9
import net.leanix.githubagent.dto.GitHubSearchResponse
9
10
import net.leanix.githubagent.dto.Installation
10
11
import net.leanix.githubagent.dto.InstallationTokenResponse
11
12
import net.leanix.githubagent.dto.ItemResponse
13
+ import net.leanix.githubagent.dto.ManifestFilesDTO
12
14
import net.leanix.githubagent.dto.Organization
13
15
import net.leanix.githubagent.dto.PagedRepositories
14
16
import net.leanix.githubagent.dto.RepositoryDto
15
17
import net.leanix.githubagent.dto.RepositoryItemResponse
16
18
import net.leanix.githubagent.exceptions.JwtTokenNotFound
17
19
import net.leanix.githubagent.graphql.data.enums.RepositoryVisibility
20
+ import net.leanix.githubagent.shared.MANIFEST_FILE_NAME
21
+ import org.junit.jupiter.api.Assertions.assertEquals
18
22
import org.junit.jupiter.api.BeforeEach
19
23
import org.junit.jupiter.api.Test
20
24
import org.junit.jupiter.api.assertThrows
@@ -163,4 +167,51 @@ class GitHubScanningServiceTest {
163
167
verify { syncLogService.sendInfoLog(" Finished initial full scan for organization testInstallation" ) }
164
168
verify { syncLogService.sendInfoLog(" Finished full scan for all available organizations" ) }
165
169
}
170
+
171
+ @Test
172
+ fun `scanGitHubResources should send manifest files with empty path if the file is in the root directory` () {
173
+ // given
174
+ every { cachingService.get(" runId" ) } returns runId
175
+ every { gitHubGraphQLService.getRepositories(any(), any()) } returns PagedRepositories (
176
+ repositories = listOf (
177
+ RepositoryDto (
178
+ id = " repo1" ,
179
+ name = " TestRepo" ,
180
+ organizationName = " testOrg" ,
181
+ description = " A test repository" ,
182
+ url = " https://github.com/testRepo" ,
183
+ archived = false ,
184
+ visibility = RepositoryVisibility .PUBLIC ,
185
+ updatedAt = " 2024-01-01T00:00:00Z" ,
186
+ languages = listOf (" Kotlin" , " Java" ),
187
+ topics = listOf (" test" , " example" ),
188
+ )
189
+ ),
190
+ hasNextPage = false ,
191
+ cursor = null
192
+ )
193
+ every { gitHubClient.searchManifestFiles(any(), any()) } returns GitHubSearchResponse (
194
+ 1 ,
195
+ listOf (
196
+ ItemResponse (
197
+ name = " leanix.yaml" ,
198
+ path = MANIFEST_FILE_NAME ,
199
+ repository = RepositoryItemResponse (
200
+ name = " TestRepo" ,
201
+ fullName = " testOrg/TestRepo"
202
+ ),
203
+ url = " http://url"
204
+ )
205
+ )
206
+ )
207
+ every { gitHubGraphQLService.getManifestFileContent(any(), any(), MANIFEST_FILE_NAME , any()) } returns " content"
208
+ val fileSlot = slot<ManifestFilesDTO >()
209
+
210
+ // when
211
+ gitHubScanningService.scanGitHubResources()
212
+
213
+ // then
214
+ verify { webSocketService.sendMessage(eq(" $runId /manifestFiles" ), capture(fileSlot)) }
215
+ assertEquals(fileSlot.captured.manifestFiles[0 ].path, " " )
216
+ }
166
217
}
0 commit comments