Skip to content

Commit

Permalink
test(bazel): Add a missing test for when there is no lockfile
Browse files Browse the repository at this point in the history
This is a test for 1045f89.

Signed-off-by: Nicolas Nobelis <[email protected]>
  • Loading branch information
nnobelis committed Oct 7, 2024
1 parent f6d5833 commit dfbd4a7
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
project:
id: "Bazel::plugins/package-managers/bazel/src/funTest/assets/projects/synthetic/bazel-no-lock-file/MODULE.bazel:"
definition_file_path: "<REPLACE_DEFINITION_FILE_PATH>"
declared_licenses: []
declared_licenses_processed: {}
vcs:
type: "Git"
url: "<REPLACE_URL_PROCESSED>"
revision: "<REPLACE_REVISION>"
path: "<REPLACE_PATH>"
vcs_processed:
type: "Git"
url: "<REPLACE_URL_PROCESSED>"
revision: "<REPLACE_REVISION>"
path: "<REPLACE_PATH>"
homepage_url: ""
scopes:
- name: "dev"
dependencies: []
- name: "main"
dependencies:
- id: "Bazel::glog:0.5.0"
linkage: "STATIC"
dependencies:
- id: "Bazel::gflags:2.2.2"
linkage: "STATIC"
packages:
- id: "Bazel::gflags:2.2.2"
purl: "pkg:generic/[email protected]"
declared_licenses: []
declared_licenses_processed: {}
description: ""
homepage_url: "https://gflags.github.io/gflags/"
binary_artifact:
url: ""
hash:
value: ""
algorithm: ""
source_artifact:
url: "https://github.com/gflags/gflags/archive/refs/tags/v2.2.2.tar.gz"
hash:
value: "34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf"
algorithm: "SHA-256"
vcs:
type: "Git"
url: "https://github.com/gflags/gflags"
revision: ""
path: ""
vcs_processed:
type: "Git"
url: "https://github.com/gflags/gflags.git"
revision: ""
path: ""
- id: "Bazel::glog:0.5.0"
purl: "pkg:generic/[email protected]"
declared_licenses: []
declared_licenses_processed: {}
description: ""
homepage_url: "https://github.com/google/glog"
binary_artifact:
url: ""
hash:
value: ""
algorithm: ""
source_artifact:
url: "https://github.com/google/glog/archive/refs/tags/v0.5.0.tar.gz"
hash:
value: "eede71f28371bf39aa69b45de23b329d37214016e2055269b3b5e7cfd40b59f5"
algorithm: "SHA-256"
vcs:
type: "Git"
url: "https://github.com/google/glog"
revision: ""
path: ""
vcs_processed:
type: "Git"
url: "https://github.com/google/glog.git"
revision: ""
path: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
common --lockfile_mode=off

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 = "glog", version = "0.5.0", repo_name = "com_github_google_glog")
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cc_library(
name = "cookie-jar",
srcs = ["cookie-jar.cc"],
hdrs = ["cookie-jar.h"],
visibility = ["//main:__pkg__", "//test:__pkg__"],
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "lib/cookie-jar.h"

int grab_cookies() {
return 42;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef LIB_COOKIE_JAR_H_
#define LIB_COOKIE_JAR_H_

int grab_cookies();

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cc_binary(
name = "main",
srcs = [
"main.cc",
],
deps = [
"//lib:cookie-jar",
"@com_github_google_glog//:glog",
],
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "lib/cookie-jar.h"
#include <glog/logging.h>

int main(int argc, char* argv[]) {
google::InitGoogleLogging(argv[0]);

int num_cookies = grab_cookies();
LOG(INFO) << "Found " << num_cookies << " cookies";
}

11 changes: 11 additions & 0 deletions plugins/package-managers/bazel/src/funTest/kotlin/BazelFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,15 @@ class BazelFunTest : StringSpec({

result.toYaml() should matchExpectedResult(expectedResultFile, definitionFile)
}

"Dependencies are detected correctly even if no lock file is present and its generation is disabled" {
val definitionFile = getAssetFile("projects/synthetic/bazel-no-lock-file/MODULE.bazel")
val expectedResultFile = getAssetFile(
"projects/synthetic/bazel-expected-output-no-lock-file.yml"
)

val result = create("Bazel").resolveSingleProject(definitionFile)

result.toYaml() should matchExpectedResult(expectedResultFile, definitionFile)
}
})

0 comments on commit dfbd4a7

Please sign in to comment.