|
| 1 | +/** |
| 2 | + * Copyright 2025 actions-toolkit authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import {describe, expect, it, jest, test} from '@jest/globals'; |
| 18 | +import * as semver from 'semver'; |
| 19 | + |
| 20 | +import {Exec} from '../../src/exec'; |
| 21 | +import {Cosign} from '../../src/cosign/cosign'; |
| 22 | + |
| 23 | +describe('isAvailable', () => { |
| 24 | + it('checks Cosign is available', async () => { |
| 25 | + const execSpy = jest.spyOn(Exec, 'getExecOutput'); |
| 26 | + const cosign = new Cosign(); |
| 27 | + await cosign.isAvailable(); |
| 28 | + // eslint-disable-next-line jest/no-standalone-expect |
| 29 | + expect(execSpy).toHaveBeenCalledWith(`cosign`, [], { |
| 30 | + silent: true, |
| 31 | + ignoreReturnCode: true |
| 32 | + }); |
| 33 | + }); |
| 34 | +}); |
| 35 | + |
| 36 | +describe('printVersion', () => { |
| 37 | + it('prints Cosign version', async () => { |
| 38 | + const execSpy = jest.spyOn(Exec, 'exec'); |
| 39 | + const cosign = new Cosign(); |
| 40 | + await cosign.printVersion(); |
| 41 | + expect(execSpy).toHaveBeenCalledWith(`cosign`, ['version', '--json'], { |
| 42 | + failOnStdErr: false |
| 43 | + }); |
| 44 | + }); |
| 45 | +}); |
| 46 | + |
| 47 | +describe('version', () => { |
| 48 | + it('valid', async () => { |
| 49 | + const cosign = new Cosign(); |
| 50 | + expect(semver.valid(await cosign.version())).not.toBeUndefined(); |
| 51 | + }); |
| 52 | +}); |
| 53 | + |
| 54 | +describe('versionSatisfies', () => { |
| 55 | + test.each([ |
| 56 | + ['v0.4.1', '>=0.3.2', true], |
| 57 | + ['v0.8.0', '>0.6.0', true], |
| 58 | + ['v0.8.0', '<0.3.0', false] |
| 59 | + ])('given %p', async (version, range, expected) => { |
| 60 | + const cosign = new Cosign(); |
| 61 | + expect(await cosign.versionSatisfies(range, version)).toBe(expected); |
| 62 | + }); |
| 63 | +}); |
0 commit comments