From d6589669fd844b5425406281625c628075bf7fc1 Mon Sep 17 00:00:00 2001
From: Tobias Schlatter <schlatter.tobias@gmail.com>
Date: Thu, 13 Feb 2025 12:53:57 +0100
Subject: [PATCH] test(bazel-module): test context failure cases with public
 interface (#34206)

---
 .../manager/bazel-module/context.spec.ts      | 46 +++++++------------
 lib/modules/manager/bazel-module/context.ts   |  7 +--
 2 files changed, 20 insertions(+), 33 deletions(-)

diff --git a/lib/modules/manager/bazel-module/context.spec.ts b/lib/modules/manager/bazel-module/context.spec.ts
index 2cf9c71a9f..1ee4ca3c8a 100644
--- a/lib/modules/manager/bazel-module/context.spec.ts
+++ b/lib/modules/manager/bazel-module/context.spec.ts
@@ -119,39 +119,25 @@ describe('modules/manager/bazel-module/context', () => {
       });
     });
 
-    describe('.currentRule', () => {
-      it('returns the record fragment if it is current', () => {
-        const ctx = new Ctx().startRule('dummy');
-        expect(ctx.currentRule).toEqual(fragments.rule('dummy'));
-      });
-
-      it('throws if there is no current', () => {
-        const ctx = new Ctx();
-        expect(() => ctx.currentRule).toThrow(
-          new Error('Requested current, but no value.'),
-        );
-      });
-
-      it('throws if the current is not a rule fragment', () => {
-        const ctx = new Ctx().startArray();
-        expect(() => ctx.currentRule).toThrow(
-          new Error('Requested current rule, but does not exist.'),
-        );
-      });
+    it('throws on missing current', () => {
+      const ctx = new Ctx();
+      expect(() => ctx.endRule()).toThrow(
+        new Error('Requested current, but no value.'),
+      );
     });
 
-    describe('.currentArray', () => {
-      it('returns the array fragment if it is current', () => {
-        const ctx = new Ctx().startArray();
-        expect(ctx.currentArray).toEqual(fragments.array());
-      });
+    it('throws on unbalanced endRule', () => {
+      const ctx = new Ctx().startRule('foo').startArray();
+      expect(() => ctx.endRule()).toThrow(
+        new Error('Requested current rule, but does not exist.'),
+      );
+    });
 
-      it('throws if the current is not an array fragment', () => {
-        const ctx = new Ctx().startRule('dummy');
-        expect(() => ctx.currentArray).toThrow(
-          new Error('Requested current array, but does not exist.'),
-        );
-      });
+    it('throws on unbalanced endArray', () => {
+      const ctx = new Ctx().startArray().startRule('dummy');
+      expect(() => ctx.endArray()).toThrow(
+        new Error('Requested current array, but does not exist.'),
+      );
     });
 
     it('throws if add an attribute without a parent', () => {
diff --git a/lib/modules/manager/bazel-module/context.ts b/lib/modules/manager/bazel-module/context.ts
index 6ad1a20ea1..70342f59ec 100644
--- a/lib/modules/manager/bazel-module/context.ts
+++ b/lib/modules/manager/bazel-module/context.ts
@@ -48,7 +48,8 @@ export class Ctx implements CtxCompatible {
     }
     return c;
   }
-  get currentRule(): RuleFragment {
+
+  private get currentRule(): RuleFragment {
     const current = this.current;
     if (current.type === 'rule') {
       return current;
@@ -56,7 +57,7 @@ export class Ctx implements CtxCompatible {
     throw new Error('Requested current rule, but does not exist.');
   }
 
-  get currentExtensionTag(): ExtensionTagFragment {
+  private get currentExtensionTag(): ExtensionTagFragment {
     const current = this.current;
     if (current.type === 'extensionTag') {
       return current;
@@ -64,7 +65,7 @@ export class Ctx implements CtxCompatible {
     throw new Error('Requested current extension tag, but does not exist.');
   }
 
-  get currentArray(): ArrayFragment {
+  private get currentArray(): ArrayFragment {
     const current = this.current;
     if (current.type === 'array') {
       return current;
-- 
GitLab