-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(scanner): Add branch name to FossID scan code
Add branch name (revision) to FossID scan code for easier identification of scanned source code. As FossID accepts maximum of 255 characters in scan code, branch name is trimmed to size, that is compliant with this constraint. Signed-off-by: Kamil Bielecki <[email protected]>
- Loading branch information
Kamil Bielecki
committed
May 24, 2024
1 parent
833dac3
commit f1628a0
Showing
3 changed files
with
132 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
plugins/scanners/fossid/src/test/kotlin/FossIdNamingProviderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright (C) 2021 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* License-Filename: LICENSE | ||
*/ | ||
|
||
package org.ossreviewtoolkit.plugins.scanners.fossid | ||
|
||
import io.kotest.core.spec.style.WordSpec | ||
import io.kotest.matchers.equals.shouldBeEqual | ||
import io.kotest.matchers.ints.shouldBeLessThanOrEqual | ||
|
||
import io.mockk.every | ||
import io.mockk.mockkStatic | ||
|
||
import java.time.LocalDateTime | ||
|
||
class FossIdNamingProviderTest : WordSpec({ | ||
"createScanCode" should { | ||
val namingProvider = FossIdNamingProvider(null, null, emptyMap()) | ||
|
||
val mockedDateTime = LocalDateTime.of(2024, 4, 1, 10, 0) | ||
val expectedTimestamp = "20240401_100000" | ||
|
||
"create code without branch name, when it's empty" { | ||
mockkStatic(LocalDateTime::class) { | ||
every { LocalDateTime.now() } returns mockedDateTime | ||
|
||
namingProvider.createScanCode( | ||
"example-project-name", null, "" | ||
) shouldBeEqual "example-project-name_$expectedTimestamp" | ||
} | ||
} | ||
|
||
"create code with branch name" { | ||
mockkStatic(LocalDateTime::class) { | ||
every { LocalDateTime.now() } returns mockedDateTime | ||
|
||
namingProvider.createScanCode( | ||
"example-project-name", null, "CODE-2233_Red-dots-added-to-layout" | ||
) shouldBeEqual "example-project-name_" + expectedTimestamp + "_CODE-2233_Red-dots-added-to-layout" | ||
} | ||
} | ||
|
||
"create code with branch name and delta tag" { | ||
mockkStatic(LocalDateTime::class) { | ||
every { LocalDateTime.now() } returns mockedDateTime | ||
|
||
namingProvider.createScanCode( | ||
"example-project-name", FossId.DeltaTag.DELTA, "CODE-2233_Red-dots-added-to-layout" | ||
) shouldBeEqual "example-project-name_" + expectedTimestamp + | ||
"_delta_CODE-2233_Red-dots-added-to-layout" | ||
} | ||
} | ||
|
||
"remove all non-standard signs from branch name when creating code" { | ||
mockkStatic(LocalDateTime::class) { | ||
every { LocalDateTime.now() } returns mockedDateTime | ||
|
||
namingProvider.createScanCode( | ||
"example-project-name", null, "feature/CODE-12%%$@@&^_SOME_*&^#!*text!!" | ||
) shouldBeEqual "example-project-name_" + | ||
expectedTimestamp + "_feature_CODE-12________SOME_______text__" | ||
} | ||
} | ||
|
||
"truncate very long scan id to fit maximum length accepted by FossID (255 chars)" { | ||
val veryLongBranchName = | ||
"origin/feature/CODE-123321_some_more_detailed_description_of_what_that_feature_doing_just_to_make_" + | ||
"it_as_descriptive_as_it's_possible_otherwise_this_test_is_pointless_so_lets_add_some_more_" + | ||
"characters_to_test_it_properly_to_avoid_any_mistake_so_lets_add_some_even_more_to_it_yolo" | ||
|
||
mockkStatic(LocalDateTime::class) { | ||
every { LocalDateTime.now() } returns mockedDateTime | ||
|
||
namingProvider.createScanCode( | ||
"example-project-name", FossId.DeltaTag.DELTA, veryLongBranchName | ||
).length shouldBeLessThanOrEqual 255 | ||
} | ||
} | ||
} | ||
}) |