github.com/bazelbuild/bazel-gazelle@v0.36.1-0.20240520142334-61b277ba6fed/tests/bzlmod/utils_test.bzl (about)

     1  load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
     2  load("//internal/bzlmod:utils.bzl", "with_replaced_or_new_fields")
     3  
     4  _BEFORE_STRUCT = struct(
     5      direct = True,
     6      path = "github.com/bazelbuild/buildtools",
     7      version = "v0.0.0-20220531122519-a43aed7014c8",
     8  )
     9  
    10  _EXPECT_REPLACED_STRUCT = struct(
    11      direct = True,
    12      path = "github.com/bazelbuild/buildtools",
    13      replace = "path/to/add/replace",
    14      version = "v1.2.2",
    15  )
    16  
    17  def _with_replaced_or_new_fields_test_impl(ctx):
    18      env = unittest.begin(ctx)
    19      asserts.equals(env, _EXPECT_REPLACED_STRUCT, with_replaced_or_new_fields(
    20          _BEFORE_STRUCT,
    21          replace = "path/to/add/replace",
    22          version = "v1.2.2",
    23      ))
    24      return unittest.end(env)
    25  
    26  with_replaced_or_new_fields_test = unittest.make(_with_replaced_or_new_fields_test_impl)
    27  
    28  def utils_test_suite(name):
    29      unittest.suite(
    30          name,
    31          with_replaced_or_new_fields_test,
    32      )