|
| 1 | +// Copyright 2026 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +import {describe, it} from 'mocha'; |
| 16 | +import {expect} from 'chai'; |
| 17 | +import {LibrarianYamlUpdater} from '../../src/updaters/java/librarian-yaml'; |
| 18 | +import {Version} from '../../src/version'; |
| 19 | + |
| 20 | +const oldContent = `language: java |
| 21 | +sources: |
| 22 | + googleapis: |
| 23 | + commit: cd090841ab172574e740c214c99df00aef9c0dee |
| 24 | + sha256: 08e4b7744dc23b6e3320a3f1d05db9f40853aaf1089d06bfb8d79044b7a66f21 |
| 25 | +default: |
| 26 | + java: |
| 27 | + libraries_bom_version: 26.79.0 |
| 28 | +libraries: |
| 29 | + - name: google-cloud-java |
| 30 | + version: 1.84.0 |
| 31 | + skip_generate: true |
| 32 | + - name: shopping-css |
| 33 | + version: 0.58.0 |
| 34 | + apis: |
| 35 | + - path: google/shopping/css/v1 |
| 36 | + java: |
| 37 | + api_description_override: The CSS API is used to manage your CSS and control your CSS Products portfolio |
| 38 | + non_cloud_api: true |
| 39 | + distribution_name_override: com.google.shopping:google-shopping-css |
| 40 | + name_pretty_override: CSS API |
| 41 | + java_apis: |
| 42 | + - additional_protos: |
| 43 | + - google/cloud/common_resources.proto |
| 44 | + path: google/shopping/css/v1 |
| 45 | + product_documentation_override: https://developers.google.com/comparison-shopping-services/api |
| 46 | + - name: secretmanager |
| 47 | + version: 2.1.0 |
| 48 | + java: |
| 49 | + api_description_override: allows you to encrypt, store, manage, and audit infrastructure and application-level secrets. |
| 50 | +`; |
| 51 | + |
| 52 | +const updatedContent = `language: java |
| 53 | +sources: |
| 54 | + googleapis: |
| 55 | + commit: cd090841ab172574e740c214c99df00aef9c0dee |
| 56 | + sha256: 08e4b7744dc23b6e3320a3f1d05db9f40853aaf1089d06bfb8d79044b7a66f21 |
| 57 | +default: |
| 58 | + java: |
| 59 | + libraries_bom_version: 26.79.0 |
| 60 | +libraries: |
| 61 | + - name: google-cloud-java |
| 62 | + version: 1.85.0 |
| 63 | + skip_generate: true |
| 64 | + - name: shopping-css |
| 65 | + version: 0.59.0 |
| 66 | + apis: |
| 67 | + - path: google/shopping/css/v1 |
| 68 | + java: |
| 69 | + api_description_override: The CSS API is used to manage your CSS and control your CSS Products portfolio |
| 70 | + non_cloud_api: true |
| 71 | + distribution_name_override: com.google.shopping:google-shopping-css |
| 72 | + name_pretty_override: CSS API |
| 73 | + java_apis: |
| 74 | + - additional_protos: |
| 75 | + - google/cloud/common_resources.proto |
| 76 | + path: google/shopping/css/v1 |
| 77 | + product_documentation_override: https://developers.google.com/comparison-shopping-services/api |
| 78 | + - name: secretmanager |
| 79 | + version: 2.2.0 |
| 80 | + java: |
| 81 | + api_description_override: allows you to encrypt, store, manage, and audit infrastructure and application-level secrets. |
| 82 | +`; |
| 83 | + |
| 84 | +describe('LibrarianYamlUpdater', () => { |
| 85 | + it('updates librarian.yaml version based on versionsMap', () => { |
| 86 | + const versionsMap = new Map<string, Version>(); |
| 87 | + versionsMap.set('google-shopping-css', Version.parse('0.59.0')); |
| 88 | + versionsMap.set('google-cloud-secretmanager', Version.parse('2.2.0')); |
| 89 | + versionsMap.set('google-cloud-java', Version.parse('1.85.0')); |
| 90 | + |
| 91 | + const updater = new LibrarianYamlUpdater({ |
| 92 | + version: Version.parse('1.0.0'), // Unused |
| 93 | + versionsMap, |
| 94 | + }); |
| 95 | + const newContent = updater.updateContent(oldContent); |
| 96 | + // Compare the content to verify librarian.yaml is not reformatted. |
| 97 | + expect(newContent).to.eq(updatedContent); |
| 98 | + }); |
| 99 | + |
| 100 | + it('returns original content if versionsMap is missing', () => { |
| 101 | + const updater = new LibrarianYamlUpdater({ |
| 102 | + version: Version.parse('1.0.0'), |
| 103 | + }); |
| 104 | + const newContent = updater.updateContent(oldContent); |
| 105 | + expect(newContent).to.equal(oldContent); |
| 106 | + }); |
| 107 | + |
| 108 | + it('returns original content if no libraries match versionsMap', () => { |
| 109 | + const versionsMap = new Map<string, Version>(); |
| 110 | + versionsMap.set('non-existent', Version.parse('1.0.0')); |
| 111 | + const updater = new LibrarianYamlUpdater({ |
| 112 | + version: Version.parse('1.0.0'), |
| 113 | + versionsMap, |
| 114 | + }); |
| 115 | + const newContent = updater.updateContent(oldContent); |
| 116 | + expect(newContent).to.equal(oldContent); |
| 117 | + }); |
| 118 | +}); |
0 commit comments