From 1aba1efd203c7c3c3cf662170794ca2d092a19a7 Mon Sep 17 00:00:00 2001
From: Timo Webler <timo.webler@dkd.de>
Date: Fri, 4 Oct 2024 15:21:14 +0200
Subject: [PATCH] test(yaml): add test for YAML tags (#31244)

---
 .../manager/docker-compose/extract.spec.ts    | 27 +++++++++++++++++++
 lib/util/yaml.spec.ts                         | 18 +++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/lib/modules/manager/docker-compose/extract.spec.ts b/lib/modules/manager/docker-compose/extract.spec.ts
index b9436050d8..a089c8b465 100644
--- a/lib/modules/manager/docker-compose/extract.spec.ts
+++ b/lib/modules/manager/docker-compose/extract.spec.ts
@@ -56,6 +56,33 @@ describe('modules/manager/docker-compose/extract', () => {
       expect(res?.deps).toHaveLength(1);
     });
 
+    it('extracts can parse yaml tags for version 3', () => {
+      const compose = codeBlock`
+          web:
+            image: node:20.0.0
+            ports:
+              - "80:8000"
+          worker:
+            extends:
+              service: web
+            ports: !reset null
+      `;
+      const res = extractPackageFile(compose, '', {});
+      expect(res).toEqual({
+        deps: [
+          {
+            depName: 'node',
+            currentValue: '20.0.0',
+            currentDigest: undefined,
+            replaceString: 'node:20.0.0',
+            autoReplaceStringTemplate:
+              '{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}',
+            datasource: 'docker',
+          },
+        ],
+      });
+    });
+
     it('extracts image and replaces registry', () => {
       const compose = codeBlock`
         version: "3"
diff --git a/lib/util/yaml.spec.ts b/lib/util/yaml.spec.ts
index de9491f458..74f37c3e89 100644
--- a/lib/util/yaml.spec.ts
+++ b/lib/util/yaml.spec.ts
@@ -281,5 +281,23 @@ describe('util/yaml', () => {
         },
       });
     });
+
+    it('should parse content with yaml tags', () => {
+      expect(
+        parseSingleYaml(
+          codeBlock`
+      myObject:
+        aString: value
+        aStringWithTag: !reset null
+      `,
+          { removeTemplates: true },
+        ),
+      ).toEqual({
+        myObject: {
+          aString: 'value',
+          aStringWithTag: 'null',
+        },
+      });
+    });
   });
 });
-- 
GitLab