Skip to content

Commit

Permalink
test(bazel): MODULE.bazel files from a local registry should be ign…
Browse files Browse the repository at this point in the history
…ored

Running the Analyzer on a project depending on packages present in a local
registry currently fails with "Unable to create the AnalyzerResult as it
contains packages and projects with the same ids". This is because the
`MODULE.bazel` files present in the local registry should not be considered
as definition files (issue [1]).
This commit adds a test for this issue.

[1]: #9076

Signed-off-by: Nicolas Nobelis <[email protected]>
  • Loading branch information
nnobelis authored and sschuberth committed Sep 11, 2024
1 parent 2b2bb87 commit e571858
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
common --registry=file://%workspace%/registry/

common --registry=https://raw.githubusercontent.com/bazelbuild/bazel-central-registry/main/

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bazel_dep(name = "module_a", version = "0.0.1")
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"module_base_path": "../modulesSrc/"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module(
name = "module_a",
version = "0.0.1",
)

bazel_dep(name = "module_b", version = "0.0.1")
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"integrity": "sha256-VixL51B9xvtJl+zWSL+TXYTv4XtUcV+lz73awFJ59mg=",
"url": "https://example.com/module_a-0.0.1.zip"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"homepage": "",
"maintainers": [],
"repository": [],
"versions": [
"0.0.1"
],
"yanked_versions": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module(
name = "module_b",
version = "0.0.1",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"integrity": "sha256-VixL51B9xvtJl+zWSL+TXYTv4XtUcV+lz73awFJ59mg=",
"url": "https://example.com/module_b-0.0.1.zip"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"homepage": "",
"maintainers": [],
"repository": [],
"versions": [
"0.0.1"
],
"yanked_versions": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2024 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.packagemanagers.bazel

import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.string.shouldContain

import org.ossreviewtoolkit.analyzer.analyze
import org.ossreviewtoolkit.utils.test.getAssetFile

class BazelDetectionTest : StringSpec({
"MODULE.bazel files present in a local registry should not be considered as definition files" {
val definitionFile = getAssetFile("projects/synthetic/bazel-local-registry2/MODULE.bazel")

val exception = shouldThrow<IllegalArgumentException> {
analyze(definitionFile.parentFile, packageManagers = listOf(Bazel.Factory()))
}

exception.shouldNotBeNull {
// Running the Analyzer on a project depending on packages present in a local registry currently fails
// with this message (issue #9076). This is because the "MODULE.bazel" files present in the local
// registry should not be considered as definition files.
message shouldContain
"Unable to create the AnalyzerResult as it contains packages and projects with the same ids"
}
}
})

0 comments on commit e571858

Please sign in to comment.